Class: OnCalendar::Parser
- Inherits:
-
Object
- Object
- OnCalendar::Parser
- Defined in:
- lib/on_calendar/parser.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MAX_ITERATIONS =
4000- TIME_SEP_CHAR =
":"- DATE_SEP_CHAR =
"-"- DATETIME_SEP_CHAR =
"T"- DATETIME_SEP_REGEX =
/\d|\*#{DATETIME_SEP_CHAR}\d|\*/- SPECIAL_EXPRESSIONS =
{ minutely: "*-*-* *:*:00", hourly: "*-*-* *:00:00", daily: "*-*-* 00:00:00", monthly: "*-*-01 00:00:00", weekly: "Mon *-*-* 00:00:00", yearly: "*-01-01 00:00:00", quarterly: "*-01,04,07,10-01 00:00:00", semiannually: "*-01,07-01 00:00:00" }.freeze
Instance Attribute Summary collapse
-
#days_of_month ⇒ Object
readonly
Returns the value of attribute days_of_month.
-
#days_of_week ⇒ Object
readonly
Returns the value of attribute days_of_week.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Instance Method Summary collapse
-
#initialize(expression) ⇒ Parser
constructor
A new instance of Parser.
- #matches_any_conditions?(field:, base:) ⇒ Boolean
- #next(count = 1, clamp: timezone.now, debug: false) ⇒ Object
Constructor Details
#initialize(expression) ⇒ Parser
Returns a new instance of Parser.
26 27 28 29 |
# File 'lib/on_calendar/parser.rb', line 26 def initialize(expression) parse(expression) @expression = expression end |
Instance Attribute Details
#days_of_month ⇒ Object (readonly)
Returns the value of attribute days_of_month.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def days_of_month @days_of_month end |
#days_of_week ⇒ Object (readonly)
Returns the value of attribute days_of_week.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def days_of_week @days_of_week end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def expression @expression end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def hours @hours end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def minutes @minutes end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def months @months end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def seconds @seconds end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def timezone @timezone end |
#years ⇒ Object (readonly)
Returns the value of attribute years.
23 24 25 |
# File 'lib/on_calendar/parser.rb', line 23 def years @years end |
Instance Method Details
#matches_any_conditions?(field:, base:) ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/on_calendar/parser.rb', line 49 def matches_any_conditions?(field:, base:) send(field).each do |condition| return true if condition.match?(base) end false end |
#next(count = 1, clamp: timezone.now, debug: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/on_calendar/parser.rb', line 31 def next(count=1, clamp: timezone.now, debug: false) raise OnCalendar::Parser::Error, "Clamp must be instance of Time" unless clamp.is_a?(Time) # Translate to correct timezone and add 1.second to ensure # we get the "next" occurence and not the current Time.now clamp = clamp.in_time_zone(timezone) + 1.second results = [] count.times do result = iterate(clamp: clamp, debug: debug) break if result.nil? clamp = result + 1.second results << result end results.empty? ? nil : results end |