Class: Blackcal::WeeksOfMonthRange

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/blackcal/range/weeks_of_month_range.rb

Overview

Week of month range

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(numbers) ⇒ WeeksOfMonthRange

Initialize numbers range

Examples:

WeeksOfMonthRange.new(1)
WeeksOfMonthRange.new([1, 2])

Parameters:

  • numbers (Array<Integer>, Integer, nil)


20
21
22
# File 'lib/blackcal/range/weeks_of_month_range.rb', line 20

def initialize(numbers)
  @numbers = ArrayUtil.flatten(numbers) if numbers
end

Instance Attribute Details

#numbersArray<Integer> (readonly) Also known as: to_a

Returns numbers in range.

Returns:

  • (Array<Integer>)

    numbers in range



12
13
14
# File 'lib/blackcal/range/weeks_of_month_range.rb', line 12

def numbers
  @numbers
end

Instance Method Details

#cover?(timestamp) ⇒ Boolean

Returns true if it covers timestamp

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/blackcal/range/weeks_of_month_range.rb', line 26

def cover?(timestamp)
  return false if numbers.nil? || numbers.empty?

  numbers.include?(TimeUtil.week_of_month(timestamp))
end

#each(&block) ⇒ Object

Iterate over range

See Also:



37
38
39
# File 'lib/blackcal/range/weeks_of_month_range.rb', line 37

def each(&block)
  to_a.each(&block)
end