class Holidays::Finder::Context::Between

Public Class Methods

new(definition_search, dates_driver_builder, options_parser) click to toggle source
# File lib/holidays/finder/context/between.rb, line 5
def initialize(definition_search, dates_driver_builder, options_parser)
  @definition_search = definition_search
  @dates_driver_builder = dates_driver_builder
  @options_parser = options_parser
end

Public Instance Methods

call(start_date, end_date, options) click to toggle source
# File lib/holidays/finder/context/between.rb, line 11
def call(start_date, end_date, options)
  validate!(start_date, end_date)

  regions, observed, informal = @options_parser.call(options)
  dates_driver = @dates_driver_builder.call(start_date, end_date)

  #FIXME Why are we calling the options_parser to convert the observed/informal
  # symbols to bool and then...converting them back? O_o
  opts = gather_options(observed, informal)

  @definition_search
    .call(dates_driver, regions, opts)
    .select { |holiday| holiday[:date].between?(start_date, end_date) }
    .sort_by { |a| a[:date] }
end

Private Instance Methods

gather_options(observed, informal) click to toggle source
# File lib/holidays/finder/context/between.rb, line 34
def gather_options(observed, informal)
  opts = []

  opts << :observed if observed
  opts << :informal if informal

  opts
end
validate!(start_date, end_date) click to toggle source
# File lib/holidays/finder/context/between.rb, line 29
def validate!(start_date, end_date)
  raise ArgumentError unless start_date
  raise ArgumentError unless end_date
end