class Blackcal::MonthRange

Month range

Constants

MONTH_INVERT_MAP

Map month number to name

MONTH_MAP

Map month name to number

Attributes

months[R]

@return [Array<Symbol>] months in range

to_a[R]

@return [Array<Symbol>] months in range

Public Class Methods

new(months) click to toggle source

Initialize month range @param [Array<String>, Array<Symbol>, Array<Integer>, String, Symbol, Integer, nil] months @example

MonthRange.new(:january)

@example

MonthRange.new([:december, :january])
# 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

Public Instance Methods

cover?(timestamp) click to toggle source

Returns true if it covers timestamp @return [Boolean]

# File lib/blackcal/range/month_range.rb, line 48
def cover?(timestamp)
  return false if @months.nil? || @months.empty?

  months.any? do |month|
    MONTH_MAP.fetch(month) == timestamp.month
  end
end
each(&block) click to toggle source

Iterate over range @see to_a

# File lib/blackcal/range/month_range.rb, line 61
def each(&block)
  to_a.each(&block)
end