Class: Eventual::Node

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/eventual/syntax_nodes.rb

Direct Known Subclasses

Day, Period

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#monthObject

Returns the value of attribute month.



55
56
57
# File 'lib/eventual/syntax_nodes.rb', line 55

def month
  @month
end

#timesObject

Returns the value of attribute times.



57
58
59
# File 'lib/eventual/syntax_nodes.rb', line 57

def times
  @times
end

#weekdaysObject

Returns the value of attribute weekdays.



56
57
58
# File 'lib/eventual/syntax_nodes.rb', line 56

def weekdays
  @weekdays
end

#yearObject

Returns the value of attribute year.



54
55
56
# File 'lib/eventual/syntax_nodes.rb', line 54

def year
  @year
end

Instance Method Details

#date_within_weekdays?(date) ⇒ Boolean

Returns true if the weekday (as number) correspons to any allowed weekday

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/eventual/syntax_nodes.rb', line 71

def date_within_weekdays? date
  return true unless weekdays
  weekdays.include? date.wday
end

#firstObject

Returns last Date or DateTime of the encompassed period



63
64
65
# File 'lib/eventual/syntax_nodes.rb', line 63

def first; 
  to_a.first 
end

#include?(date) ⇒ Boolean

Returns true if the Date or DateTime passed is included in the parsed Dates or DateTimes

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
# File 'lib/eventual/syntax_nodes.rb', line 82

def include? date
  result = false
  walk { |elements|
    break result = true if elements.include? date 
  }

  return result if !result || date.class == Date || times.nil?

  times.include? date
end

#lastObject

Returns last Date or DateTime of the encompassed period



60
# File 'lib/eventual/syntax_nodes.rb', line 60

def last; to_a.last end

#map(&block) ⇒ Object

Invokes block once for each Date or DateTime. Creates a new array containing the values returned by the block.



77
78
79
# File 'lib/eventual/syntax_nodes.rb', line 77

def map &block
  walk { |elements| elements.map &block }.compact
end

#to_aObject

Returns an array with all the encompassed Dates or DateTimes



68
# File 'lib/eventual/syntax_nodes.rb', line 68

def to_a; map{ |e| e } end