Module: HarvestTimeOff

Defined in:
lib/harvest_time_off.rb,
lib/harvest_time_off/version.rb,
lib/harvest_time_off/work_entry_cli.rb

Defined Under Namespace

Classes: CLI, Error, WorkEntryCLI

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.dates_between(from, to, holiday_regions:) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/harvest_time_off.rb', line 13

def dates_between(from, to, holiday_regions:)
  raise Error, "end date must not be before start date" if to < from
  raise Error, "at least one holiday region is required" if holiday_regions.empty?

  holidays = Holidays.between(from, to, *(holiday_regions.map { |region| region.downcase.to_sym } + [:observed])).map { |holiday| holiday[:date] }
  (from..to).select { |date| date.workday?(holidays:) }
rescue Holidays::InvalidRegion
  raise Error, "invalid holiday region: #{holiday_regions.join(", ")}"
end

.display_hours(hours) ⇒ Object



23
24
25
# File 'lib/harvest_time_off.rb', line 23

def display_hours(hours)
  format("%g", hours)
end