Skip to content

Commit

Permalink
Refactor model building for maintainability.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 24, 2018
1 parent b0939de commit dce482d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/cff/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,18 @@ def method_missing(name, *args) # :nodoc:
private

def build_model(fields)
fields['authors'].each do |a|
@authors << (a.has_key?('given-names') ? Person.new(a) : Entity.new(a))
end

fields['contact'].each do |a|
@contact << (a.has_key?('given-names') ? Person.new(a) : Entity.new(a))
end
build_entity_collection(@authors, fields['authors'])
build_entity_collection(@contact, fields['contact'])

@fields = delete_from_hash(fields, 'authors', 'contact')
end

def build_entity_collection(field, source)
source.each do |s|
field << (s.has_key?('given-names') ? Person.new(s) : Entity.new(s))
end
end

def array_field_to_yaml(field)
field.reject do |f|
!f.respond_to?(:fields)
Expand Down

0 comments on commit dce482d

Please sign in to comment.