Class: Chronik::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/chronik/label.rb

Overview

The class of days.

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Label

Returns a new instance of Label.



6
7
8
# File 'lib/chronik/label.rb', line 6

def initialize(text)
  @tokens = text.split.map{|word| Unicode.downcase(word).to_sym} - SUGAR
end

Instance Method Details

#holidays(range = (Date.today..Date.today.next_month)) ⇒ Object

Special days which are represented by this label. Those are probably one in a year holidays like Christmas.

range - [Range]:

Returns an Array of Dates.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chronik/label.rb', line 16

def holidays(range=(Date.today..Date.today.next_month))
  output = []
  @tokens.each do |token|
    if ALL_HOLIDAYS.include?(token)
      return HOLIDAYS.values.map do |dates|
        dates.call(range)
      end.flatten.uniq
    end
    HOLIDAYS.each_pair do |labels,dates|
      if labels.include?(token)
        output.concat(dates.call(range))
      end
    end
  end
  output
end

#weekdaysObject

Day(s) of a week (Sunday is 0). Also range of days, like weekend.

Returns an Array of Integers.



36
37
38
39
40
41
42
43
# File 'lib/chronik/label.rb', line 36

def weekdays
  @tokens.each do |token|
    WEEKDAYS.each_pair do |labels,wdays|
      return wdays if labels.include?(token)
    end
  end
  []
end