Class: DateHolidays::Reader::Holiday
- Inherits:
-
Object
- Object
- DateHolidays::Reader::Holiday
- Defined in:
- lib/date_holidays/reader/holiday.rb
Overview
A holiday which includes a date, start and end times, name, and type. Based on github.com/commenthol/date-holidays#holiday-object .
The date is represented as a Ruby Date instance as it is the holiday start date in the local time zone.
Start and end times are represented as Time instances in UTC. Note that New Year’s day in the US has a start time of January 1st at 5 AM UTC as Eastern Standard Time is five hours after UTC.
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity I could cut down on those cops by iterating over instance variable and using meta programming.
-
#initialize(date:, start_time:, end_time:, name:, type:, substitute: false, note: nil) ⇒ Holiday
constructor
rubocop:disable Metrics/ParameterLists This cop defaults to five parameters which seems a little low for keyword arguments.
- #substitute? ⇒ Boolean
Constructor Details
#initialize(date:, start_time:, end_time:, name:, type:, substitute: false, note: nil) ⇒ Holiday
rubocop:disable Metrics/ParameterLists This cop defaults to five parameters which seems a little low for keyword arguments. This is a value object which gets frozen after initialization so I’d rather pass in everything as needed right away.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/date_holidays/reader/holiday.rb', line 33 def initialize(date:, start_time:, end_time:, name:, type:, substitute: false, note: nil) # rubocop:enable Metrics/ParameterLists @date = date.respond_to?(:to_date) ? date.to_date : Date.strptime(date, '%Y-%m-%d') @start_time = parse_time(start_time) @end_time = parse_time(end_time) @name = name @type = type.to_sym @substitute = substitute @note = note freeze end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
27 28 29 |
# File 'lib/date_holidays/reader/holiday.rb', line 27 def date @date end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
27 28 29 |
# File 'lib/date_holidays/reader/holiday.rb', line 27 def end_time @end_time end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/date_holidays/reader/holiday.rb', line 27 def name @name end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
27 28 29 |
# File 'lib/date_holidays/reader/holiday.rb', line 27 def note @note end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
27 28 29 |
# File 'lib/date_holidays/reader/holiday.rb', line 27 def start_time @start_time end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/date_holidays/reader/holiday.rb', line 27 def type @type end |
Instance Method Details
#==(other) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity I could cut down on those cops by iterating over instance variable and using meta programming. However, that would obscure intent.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/date_holidays/reader/holiday.rb', line 53 def ==(other) other.is_a?(self.class) && other.date == date && other.start_time == start_time && other.end_time == end_time && other.name == name && other.type == type && other.substitute? == substitute? && other.note == note end |
#substitute? ⇒ Boolean
46 47 48 |
# File 'lib/date_holidays/reader/holiday.rb', line 46 def substitute? @substitute end |