Module: DataReader
- Defined in:
- lib/data_reader.rb,
lib/data_reader/version.rb
Constant Summary collapse
- VERSION =
"2.0.0".freeze
Instance Method Summary collapse
-
#data_contents ⇒ Object
Returns the contents that have been read in from a loaded file data file.
-
#data_path ⇒ Object
Returns the path that will be used to read data files.
-
#data_path=(path) ⇒ Object
Sets the path to use when reading data files.
- #include_data(file) ⇒ Object
- #load(file_list) ⇒ Object
Instance Method Details
#data_contents ⇒ Object
Returns the contents that have been read in from a loaded file data file.
22 23 24 25 26 |
# File 'lib/data_reader.rb', line 22 def data_contents return @data_contents if @data_contents nil end |
#data_path ⇒ Object
Returns the path that will be used to read data files.
14 15 16 17 18 19 |
# File 'lib/data_reader.rb', line 14 def data_path return @data_path if @data_path return default_data_path if respond_to? :default_data_path nil end |
#data_path=(path) ⇒ Object
Sets the path to use when reading data files.
9 10 11 |
# File 'lib/data_reader.rb', line 9 def data_path=(path) @data_path = path end |
#include_data(file) ⇒ Object
38 39 40 41 |
# File 'lib/data_reader.rb', line 38 def include_data(file) filename = Pathname.new(file).absolute? ? file : "#{data_path}/#{file}" ERB.new(IO.read(filename)).result(binding) if File.exist?(filename) end |
#load(file_list) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/data_reader.rb', line 28 def load(file_list) files = file_list.include?(',') ? file_list.split(',') : [file_list] files = files.collect(&:strip) @data_contents = files.inject({}) do |all_data, file| data = include_key(::YAML.safe_load(include_data(file))) all_data.merge!(data) if data end end |