Class: Wpxf::DataFile

Inherits:
Object
  • Object
show all
Defined in:
lib/wpxf/core/data_file.rb

Overview

Represents a data file found in the data directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*path_parts) ⇒ DataFile

Initialize a new instance of Wpxf::DataFile.

Parameters:

  • path_parts

    the path to the file, relative to the data directory.



8
9
10
# File 'lib/wpxf/core/data_file.rb', line 8

def initialize(*path_parts)
  self.content = File.read(File.join(Wpxf.data_directory, path_parts))
end

Instance Attribute Details

#contentObject

Returns the content of the file.

Returns:

  • the content of the file.



25
26
27
# File 'lib/wpxf/core/data_file.rb', line 25

def content
  @content
end

Instance Method Details

#content_with_named_vars(vars) ⇒ String

Returns the contents of the data file with variable replacements.

Returns:

  • (String)

    the contents of the data file with variable replacements.



19
20
21
22
# File 'lib/wpxf/core/data_file.rb', line 19

def content_with_named_vars(vars)
  matcher = /#{vars.keys.map { |k| Regexp.escape(k) }.join('|')}/
  content.gsub(matcher, vars)
end

#php_contentString

Returns the contents of a PHP data file without the surrounding <?php ?> tags.

Returns:

  • (String)

    the contents of a PHP data file without the surrounding <?php ?> tags.



14
15
16
# File 'lib/wpxf/core/data_file.rb', line 14

def php_content
  content.strip.sub(/^<\?php/i, '').sub(/\?>$/i, '')
end