Class: Blackcal::DayRange

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

Overview

Day range

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(numbers) ⇒ DayRange

Initialize numbers range

Examples:

DayRange.new(1)
DayRange.new([1, 2])
DayRange.new([9..10, 13..14])

Parameters:

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


21
22
23
# File 'lib/blackcal/range/day_range.rb', line 21

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



11
12
13
# File 'lib/blackcal/range/day_range.rb', line 11

def numbers
  @numbers
end

Instance Method Details

#cover?(timestamp) ⇒ Boolean

Returns true if it covers timestamp

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/blackcal/range/day_range.rb', line 27

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

  numbers.include?(timestamp.day)
end

#each(&block) ⇒ Object

Iterate over range

See Also:



38
39
40
# File 'lib/blackcal/range/day_range.rb', line 38

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