Skip to content

Commit

Permalink
Update #key_dates accessor to handle ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Dec 12, 2017
1 parent 1d15fa9 commit d19a89a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/mods/origin_info.rb
Expand Up @@ -13,7 +13,9 @@ def dates
end

def key_dates
dates.select { |x| x.keyDate == 'yes' }
d = dates.select { |x| x.keyDate == 'yes' }

d += dates.select { |x| x.point == 'end' && d.any? { |date| date.name == x.name && date.point == 'start' } }
end
end
end
5 changes: 5 additions & 0 deletions spec/origin_info_spec.rb
Expand Up @@ -249,6 +249,11 @@
@mods_rec.from_str("<mods #{@ns_decl}><originInfo><dateCreated>other date</dateCreated><dateCreated keyDate='yes'>key date</dateCreated></originInfo></mods>")
expect(@mods_rec.origin_info.as_object.first.key_dates.first.text).to eq 'key date'
end
it 'should extract a date range when the keyDate attribute is on the start of the range' do
@mods_rec.from_str("<mods #{@ns_decl}><originInfo><dateCreated point='end'>other date</dateCreated><dateCreated keyDate='yes' point='start'>key date</dateCreated></originInfo></mods>")
expect(@mods_rec.origin_info.as_object.first.key_dates.first.text).to eq 'key date'
expect(@mods_rec.origin_info.as_object.first.key_dates.last.text).to eq 'other date'
end
end
end

Expand Down

0 comments on commit d19a89a

Please sign in to comment.