Module: DataReader

Defined in:
lib/data_reader.rb,
lib/data_reader/version.rb

Constant Summary collapse

VERSION =
"1.0.2".freeze

Instance Method Summary collapse

Instance Method Details

#data_pathObject



10
11
12
13
14
# File 'lib/data_reader.rb', line 10

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



6
7
8
# File 'lib/data_reader.rb', line 6

def data_path=(path)
  @data_path = path
end

#data_sourceObject



16
17
18
19
# File 'lib/data_reader.rb', line 16

def data_source
  return @data_source if @data_source
  nil
end

#include_data(filename) ⇒ Object



31
32
33
# File 'lib/data_reader.rb', line 31

def include_data(filename)
  ERB.new(IO.read("#{data_path}/#{filename}")).result
end

#load(file_list) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/data_reader.rb', line 21

def load(file_list)
  files = file_list.include?(',') ? file_list.split(',') : [file_list]
  files = files.collect(&:strip)
  @data_source = files.inject({}) do |data, file|
    data.merge!(YAML.safe_load(
                  ERB.new(File.read("#{data_path}/#{file}")).result(binding)
    ))
  end
end