Class: Chronic::Repeater
Direct Known Subclasses
RepeaterDay, RepeaterDayName, RepeaterDayPortion, RepeaterFortnight, RepeaterHour, RepeaterMinute, RepeaterMonth, RepeaterMonthName, RepeaterQuarter, RepeaterSeason, RepeaterSecond, RepeaterTime, RepeaterWeek, RepeaterWeekday, RepeaterWeekend, RepeaterYear
Instance Attribute Summary
Attributes inherited from Tag
Class Method Summary collapse
-
.scan(tokens, options) ⇒ Object
Scan an Array of Token objects and apply any necessary Repeater tags to each token.
-
.scan_for_day_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
-
.scan_for_day_portions(token, options = {}) ⇒ Object
token - The Token object we want to scan.
-
.scan_for_month_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
-
.scan_for_quarter_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
-
.scan_for_season_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
-
.scan_for_times(token, options = {}) ⇒ Object
token - The Token object we want to scan.
-
.scan_for_units(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#next(pointer) ⇒ Object
returns the next occurance of this repeatable.
- #this(pointer) ⇒ Object
- #to_s ⇒ Object
-
#width ⇒ Object
returns the width (in seconds or months) of this repeatable.
Methods inherited from Tag
Constructor Details
This class inherits a constructor from Chronic::Tag
Class Method Details
.scan(tokens, options) ⇒ Object
Scan an Array of Token objects and apply any necessary Repeater tags to each token.
tokens - An Array of tokens to scan. options - The Hash of options specified in Chronic::parse.
Returns an Array of tokens.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/chronic/tags/repeater.rb', line 11 def self.scan(tokens, ) tokens.each do |token| token.tag scan_for_quarter_names(token, ) token.tag scan_for_season_names(token, ) token.tag scan_for_month_names(token, ) token.tag scan_for_day_names(token, ) token.tag scan_for_day_portions(token, ) token.tag scan_for_times(token, ) token.tag scan_for_units(token, ) end end |
.scan_for_day_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/chronic/tags/repeater.rb', line 73 def self.scan_for_day_names(token, = {}) scan_for token, RepeaterDayName, { /^m[ou]n(day)?$/ => :monday, /^t(ue|eu|oo|u)s?(day)?$/ => :tuesday, /^we(d|dnes|nds|nns)(day)?$/ => :wednesday, /^th(u|ur|urs|ers)(day)?$/ => :thursday, /^fr[iy](day)?$/ => :friday, /^sat(t?[ue]rday)?$/ => :saturday, /^su[nm](day)?$/ => :sunday }, end |
.scan_for_day_portions(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/chronic/tags/repeater.rb', line 89 def self.scan_for_day_portions(token, = {}) scan_for token, RepeaterDayPortion, { /^ams?$/ => :am, /^pms?$/ => :pm, /^mornings?$/ => :morning, /^afternoons?$/ => :afternoon, /^evenings?$/ => :evening, /^(night|nite)s?$/ => :night }, end |
.scan_for_month_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/chronic/tags/repeater.rb', line 52 def self.scan_for_month_names(token, = {}) scan_for token, RepeaterMonthName, { /^jan[:\.]?(uary)?$/ => :january, /^feb[:\.]?(ruary)?$/ => :february, /^mar[:\.]?(ch)?$/ => :march, /^apr[:\.]?(il)?$/ => :april, /^may$/ => :may, /^jun[:\.]?e?$/ => :june, /^jul[:\.]?y?$/ => :july, /^aug[:\.]?(ust)?$/ => :august, /^sep[:\.]?(t[:\.]?|tember)?$/ => :september, /^oct[:\.]?(ober)?$/ => :october, /^nov[:\.]?(ember)?$/ => :november, /^dec[:\.]?(ember)?$/ => :december }, end |
.scan_for_quarter_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
26 27 28 29 30 31 32 33 34 |
# File 'lib/chronic/tags/repeater.rb', line 26 def self.scan_for_quarter_names(token, = {}) scan_for token, RepeaterQuarterName, { /^q1$/ => :q1, /^q2$/ => :q2, /^q3$/ => :q3, /^q4$/ => :q4 }, end |
.scan_for_season_names(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
39 40 41 42 43 44 45 46 47 |
# File 'lib/chronic/tags/repeater.rb', line 39 def self.scan_for_season_names(token, = {}) scan_for token, RepeaterSeasonName, { /^springs?$/ => :spring, /^summers?$/ => :summer, /^(autumn)|(fall)s?$/ => :autumn, /^winters?$/ => :winter }, end |
.scan_for_times(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
104 105 106 |
# File 'lib/chronic/tags/repeater.rb', line 104 def self.scan_for_times(token, = {}) scan_for token, RepeaterTime, /^\d{1,2}(:?\d{1,2})?([\.:]?\d{1,2}([\.:]\d{1,6})?)?$/, end |
.scan_for_units(token, options = {}) ⇒ Object
token - The Token object we want to scan.
Returns a new Repeater object.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/chronic/tags/repeater.rb', line 111 def self.scan_for_units(token, = {}) { /^years?$/ => :year, /^q$/ => :quarter, /^seasons?$/ => :season, /^months?$/ => :month, /^fortnights?$/ => :fortnight, /^weeks?$/ => :week, /^weekends?$/ => :weekend, /^(week|business)days?$/ => :weekday, /^days?$/ => :day, /^hrs?$/ => :hour, /^hours?$/ => :hour, /^mins?$/ => :minute, /^minutes?$/ => :minute, /^secs?$/ => :second, /^seconds?$/ => :second }.each do |item, symbol| if item =~ token.word klass_name = 'Repeater' + symbol.to_s.capitalize klass = Chronic.const_get(klass_name) return klass.new(symbol, nil, ) end end return nil end |
Instance Method Details
#<=>(other) ⇒ Object
138 139 140 |
# File 'lib/chronic/tags/repeater.rb', line 138 def <=>(other) width <=> other.width end |
#next(pointer) ⇒ Object
returns the next occurance of this repeatable.
148 149 150 |
# File 'lib/chronic/tags/repeater.rb', line 148 def next(pointer) raise('Start point must be set before calling #next') unless @now end |
#this(pointer) ⇒ Object
152 153 154 |
# File 'lib/chronic/tags/repeater.rb', line 152 def this(pointer) raise('Start point must be set before calling #this') unless @now end |
#to_s ⇒ Object
156 157 158 |
# File 'lib/chronic/tags/repeater.rb', line 156 def to_s 'repeater' end |
#width ⇒ Object
returns the width (in seconds or months) of this repeatable.
143 144 145 |
# File 'lib/chronic/tags/repeater.rb', line 143 def width raise('Repeater#width must be overridden in subclasses') end |