Class: Wpxf::DataFile
- Inherits:
-
Object
- Object
- Wpxf::DataFile
- Defined in:
- lib/wpxf/core/data_file.rb
Overview
Represents a data file found in the data directory.
Instance Attribute Summary collapse
-
#content ⇒ Object
The content of the file.
Instance Method Summary collapse
-
#content_with_named_vars(vars) ⇒ String
The contents of the data file with variable replacements.
-
#initialize(*path_parts) ⇒ DataFile
constructor
Initialize a new instance of DataFile.
-
#php_content ⇒ String
The contents of a PHP data file without the surrounding <?php ?> tags.
Constructor Details
#initialize(*path_parts) ⇒ DataFile
Initialize a new instance of Wpxf::DataFile.
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
#content ⇒ Object
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.
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_content ⇒ String
Returns 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 |