Class: HolidaysFromGoogleCalendar::CacheUnit
- Inherits:
-
Object
- Object
- HolidaysFromGoogleCalendar::CacheUnit
- Defined in:
- lib/holidays_from_google_calendar/cache_unit.rb
Instance Attribute Summary collapse
-
#date_max ⇒ Object
readonly
Returns the value of attribute date_max.
-
#date_min ⇒ Object
readonly
Returns the value of attribute date_min.
-
#holidays ⇒ Object
readonly
Returns the value of attribute holidays.
Instance Method Summary collapse
- #combine(other) ⇒ Object
- #include?(date_min, date_max) ⇒ Boolean
-
#initialize(holidays, date_min, date_max) ⇒ CacheUnit
constructor
A new instance of CacheUnit.
- #overlapped?(other) ⇒ Boolean
- #retrieve(date_min, date_max) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(holidays, date_min, date_max) ⇒ CacheUnit
Returns a new instance of CacheUnit.
5 6 7 8 9 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 5 def initialize(holidays, date_min, date_max) @holidays = holidays @date_min = date_min @date_max = date_max end |
Instance Attribute Details
#date_max ⇒ Object (readonly)
Returns the value of attribute date_max.
3 4 5 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 3 def date_max @date_max end |
#date_min ⇒ Object (readonly)
Returns the value of attribute date_min.
3 4 5 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 3 def date_min @date_min end |
#holidays ⇒ Object (readonly)
Returns the value of attribute holidays.
3 4 5 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 3 def holidays @holidays end |
Instance Method Details
#combine(other) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 28 def combine(other) return unless overlapped?(other) @date_min = [@date_min, other.date_min].min @date_max = [@date_max, other.date_max].max @holidays = @holidays.concat(other.holidays).uniq.sort { |a, b| a.date <=> b.date } end |
#include?(date_min, date_max) ⇒ Boolean
15 16 17 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 15 def include?(date_min, date_max) [date_min, date_max].all? { |e| @date_min <= e && e <= @date_max } end |
#overlapped?(other) ⇒ Boolean
23 24 25 26 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 23 def overlapped?(other) (@date_min <= other.date_max && other.date_min <= @date_max + 1.day) || (other.date_min <= @date_max && @date_min <= other.date_max + 1.day) end |
#retrieve(date_min, date_max) ⇒ Object
19 20 21 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 19 def retrieve(date_min, date_max) @holidays.select { |e| date_min <= e.date && e.date <= date_max } end |
#size ⇒ Object
11 12 13 |
# File 'lib/holidays_from_google_calendar/cache_unit.rb', line 11 def size @holidays.size end |