Class: Atethechon::ContactParser

Inherits:
Object
  • Object
show all
Defined in:
lib/atethechon/parsers/contact_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ContactParser

Returns a new instance of ContactParser.



10
11
12
# File 'lib/atethechon/parsers/contact_parser.rb', line 10

def initialize(options = {})
  @data_directory = options.fetch(:data_directory) { Pathname.new(File.expand_path("../..", File.dirname(__dir__))).join("data") }
end

Instance Attribute Details

#data_directoryObject (readonly)

Returns the value of attribute data_directory.



8
9
10
# File 'lib/atethechon/parsers/contact_parser.rb', line 8

def data_directory
  @data_directory
end

Instance Method Details

#loadObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/atethechon/parsers/contact_parser.rb', line 14

def load
  Dir[data_directory.join("**/*.yml")].sort.each_with_object([]) do |data_file, result|
    data = YAML.load_file(data_file)
    data.each do |_organization_identifier, attributes|
      attributes.fetch("contacts").each do |contact_data|
        result << Contact.new(contact_data)
      end
    end
  end
end