class Blackcal::WeekdayRange
Weekday range
Constants
- WEEKDAY_INVERT_MAP
Map weekday number to name
- WEEKDAY_MAP
Map weekday name to number
Attributes
to_a[R]
@return [Array<Symbol>] weekdays in range
weekdays[R]
@return [Array<Symbol>] weekdays in range
Public Class Methods
new(weekdays)
click to toggle source
Initialize weekday range @param [Array<String>, Array<Symbol>, Array<Integer>, String, Symbol, Integer, nil] weekdays @example
WeekdayRange.new(:monday)
@example
WeekdayRange.new([:monday, :thursday])
# File lib/blackcal/range/weekday_range.rb, line 31 def initialize(weekdays) return unless weekdays @weekdays = Array(weekdays).map do |week| next WEEKDAY_INVERT_MAP.fetch(week) if week.is_a?(Integer) week.downcase.to_sym end end
Public Instance Methods
cover?(timestamp)
click to toggle source
Returns true if it covers timestamp @return [Boolean]
# File lib/blackcal/range/weekday_range.rb, line 43 def cover?(timestamp) return false if @weekdays.nil? || @weekdays.empty? weekdays.any? do |weekday| WEEKDAY_MAP.fetch(weekday) == timestamp.wday end end
each(&block)
click to toggle source
Iterate over range @see to_a
# File lib/blackcal/range/weekday_range.rb, line 56 def each(&block) to_a.each(&block) end