Class: Blackcal::MonthRange
- Inherits:
-
Object
- Object
- Blackcal::MonthRange
- Includes:
- Enumerable
- Defined in:
- lib/blackcal/range/month_range.rb
Overview
Month range
Constant Summary collapse
- MONTH_MAP =
Map month name to number
{ january: 1, february: 2, march: 3, april: 4, may: 5, june: 6, july: 7, august: 8, september: 9, october: 10, november: 11, december: 12, }.freeze
- MONTH_INVERT_MAP =
Map month number to name
MONTH_MAP.invert.freeze
Instance Attribute Summary collapse
-
#months ⇒ Array<Symbol>
(also: #to_a)
readonly
Months in range.
Instance Method Summary collapse
-
#cover?(timestamp) ⇒ Boolean
Returns true if it covers timestamp.
-
#each(&block) ⇒ Object
Iterate over range.
-
#initialize(months) ⇒ MonthRange
constructor
Initialize month range.
Constructor Details
#initialize(months) ⇒ MonthRange
Initialize month range
36 37 38 39 40 41 42 43 44 |
# File 'lib/blackcal/range/month_range.rb', line 36 def initialize(months) return unless months @months = Array(months).map do |month| next MONTH_INVERT_MAP.fetch(month) if month.is_a?(Integer) month.downcase.to_sym end end |
Instance Attribute Details
#months ⇒ Array<Symbol> (readonly) Also known as: to_a
Returns months in range.
28 29 30 |
# File 'lib/blackcal/range/month_range.rb', line 28 def months @months end |
Instance Method Details
#cover?(timestamp) ⇒ Boolean
Returns true if it covers timestamp
48 49 50 51 52 53 54 |
# File 'lib/blackcal/range/month_range.rb', line 48 def cover?() return false if @months.nil? || @months.empty? months.any? do |month| MONTH_MAP.fetch(month) == .month end end |
#each(&block) ⇒ Object
Iterate over range
61 62 63 |
# File 'lib/blackcal/range/month_range.rb', line 61 def each(&block) to_a.each(&block) end |