Skip to content

Commit

Permalink
Treat commas as date separators if left straggling at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
kspurgin committed Jan 24, 2024
1 parent b42e9da commit 4521afb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/emendate/date_segmenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def call
apply_modifiers(mod) until working.empty?
end

separators = result.select { |seg| %i[and or].include?(seg.type) }
separators = result.select { |seg| %i[and or comma].include?(seg.type) }
return Success(result) if separators.empty?

if separators.map(&:type).uniq.length > 1
Expand Down
9 changes: 9 additions & 0 deletions spec/emendate/date_segmenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
end
end

context "with ####, ####" do
let(:string) { "1997, 2000" }

it "segments as expected" do
expect(types).to eq(%i[year_date_type date_separator year_date_type])
expect(result.lexeme).to eq(string)
end
end

context "with ####/##", :unambiguous_year_year do
let(:string) { "1997/98" }

Expand Down
3 changes: 2 additions & 1 deletion spec/emendate/range_indicator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
let(:str) { "1970, 1972 - 1999, 2002" }

it "returns range_date_type" do
expect(type_string).to eq("year_date_type comma range_date_type comma "\
expect(type_string).to eq("year_date_type date_separator "\
"range_date_type date_separator "\
"year_date_type")
expect(subject.lexeme).to eq(str)
end
Expand Down

0 comments on commit 4521afb

Please sign in to comment.