Class: Atethechon::ContactParser
- Inherits:
-
Object
- Object
- Atethechon::ContactParser
- Defined in:
- lib/atethechon/parsers/contact_parser.rb
Instance Attribute Summary collapse
-
#data_directory ⇒ Object
readonly
Returns the value of attribute data_directory.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ContactParser
constructor
A new instance of ContactParser.
- #load ⇒ Object
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( = {}) @data_directory = .fetch(:data_directory) { Pathname.new(File.("../..", File.dirname(__dir__))).join("data") } end |
Instance Attribute Details
#data_directory ⇒ Object (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
#load ⇒ Object
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 |