Module: DataReader
- Defined in:
- lib/data_reader.rb,
lib/data_reader/version.rb
Constant Summary collapse
- VERSION =
"1.3.0".freeze
Instance Method Summary collapse
- #data_path ⇒ Object
- #data_path=(path) ⇒ Object
- #data_source ⇒ Object
- #include_data(file) ⇒ Object
- #load(file_list) ⇒ Object
Instance Method Details
#data_path ⇒ Object
11 12 13 14 15 |
# File 'lib/data_reader.rb', line 11 def data_path return @data_path if @data_path return default_data_path if self.respond_to? :default_data_path nil end |
#data_path=(path) ⇒ Object
7 8 9 |
# File 'lib/data_reader.rb', line 7 def data_path=(path) @data_path = path end |
#data_source ⇒ Object
17 18 19 20 21 |
# File 'lib/data_reader.rb', line 17 def data_source return @data_source if @data_source nil end |
#include_data(file) ⇒ Object
33 34 35 36 |
# File 'lib/data_reader.rb', line 33 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
23 24 25 26 27 28 29 30 31 |
# File 'lib/data_reader.rb', line 23 def load(file_list) files = file_list.include?(',') ? file_list.split(',') : [file_list] files = files.collect(&:strip) @data_source = files.inject({}) do |all_data, file| data = include_key(::YAML.safe_load(include_data(file))) all_data.merge!(data) if data end end |