Skip to content

Commit

Permalink
Merge pull request #24 from arttracks/bce_unspecified
Browse files Browse the repository at this point in the history
Added functionality to handle uncertainty masking in negative years
  • Loading branch information
inukshuk committed Feb 17, 2017
2 parents fca8450 + 86f389e commit 082d546
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/edtf/uncertainty.rb
Expand Up @@ -86,9 +86,15 @@ def to_s
end

def mask(values)
values.zip(members.take(values.length)).map do |value, mask|
if values[0] && values[0][0] == "-"
values[0].delete!("-")
negative_year = true
end
results = values.zip(members.take(values.length)).map do |value, mask|
value.split(//).zip(send(mask)).map { |v,m| m ? U : v }.join
end
results[0] = "-#{results[0]}" if negative_year
results
end
end

Expand Down
25 changes: 25 additions & 0 deletions spec/edtf/uncertainty_spec.rb
Expand Up @@ -186,6 +186,31 @@ module EDTF

end

context 'when passed an array with a negative year string' do
let(:date) { ['-1994'] }

it 'should return the array with the year by default' do
expect(u.mask(date)).to eq(['-1994'])
end

context 'when the year is unspecified' do
before(:each) { u.year[3] = true }

it 'should return the array with the year and the fourth digit masked' do
expect(u.mask(date)).to eq(['-199u'])
end
end

context 'when the decade is unspecified' do
before(:each) { u.year[2,2] = [true,true] }

it 'should return the array with the year and the third and fourth digit masked' do
expect(u.mask(date)).to eq(['-19uu'])
end

end
end

context 'when passed an array with a year-month string' do
let(:date) { ['1994', '01'] }

Expand Down

0 comments on commit 082d546

Please sign in to comment.