Module: Scruber::Helpers::DictionaryReader

Defined in:
lib/scruber/helpers/dictionary_reader.rb,
lib/scruber/helpers/dictionary_reader/csv.rb,
lib/scruber/helpers/dictionary_reader/xml.rb

Defined Under Namespace

Classes: Csv, Xml

Class Method Summary collapse

Class Method Details

.[](label) ⇒ Object



23
24
25
# File 'lib/scruber/helpers/dictionary_reader.rb', line 23

def [](label)
  _registered_types[label]
end

._registered_typesObject



27
28
29
# File 'lib/scruber/helpers/dictionary_reader.rb', line 27

def _registered_types
  @registered_types ||= {}
end

.add(label, claz) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/scruber/helpers/dictionary_reader.rb', line 15

def add(label, claz)
  unless claz.instance_methods.include?(:read)
    raise NoMethodError, "read is not declared in the #{claz.inspect}"
  end

  _registered_types[label] = claz
end

.read(file_path, file_type, options) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/scruber/helpers/dictionary_reader.rb', line 5

def read(file_path, file_type, options)
  if _registered_types.keys.include?(file_type.to_sym)
    _registered_types[file_type.to_sym].new(file_path).read(options) do |obj|
      yield obj
    end
  else
    raise "Unsupported type, supported types #{_registered_types.keys}"
  end
end