forked from IUBLibTech/archives_online
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from scientist-softserv/add-data-to-test-year-…
…facet ⚙️ Bring over `year_range` from `ngao`
- Loading branch information
Showing
2 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'arclight/year_range' | ||
|
||
module Ngao | ||
class YearRange < Arclight::YearRange | ||
# @param [String] `dates` in the form YYYY/YYYY | ||
# @return [Array<Integer>] the set of years in the given range | ||
def parse_range(dates) | ||
return if dates.blank? | ||
|
||
start_year, end_year = dates.split('/').map { |date| to_year_from_iso8601(date) } | ||
return [start_year] if end_year.blank? | ||
# Original in Arclight checks that date ranges can't be larger than 1000 years, we don't want that in NGAO | ||
# raise ArgumentError, "Range is too large: #{dates}" if (end_year - start_year) > 1000 | ||
raise ArgumentError, "Range is inverted: #{dates}" unless start_year <= end_year | ||
|
||
(start_year..end_year).to_a | ||
end | ||
end | ||
end |