Module: TimeCursor::Base
- Included in:
- TimeCursor
- Defined in:
- lib/time_cursor/base.rb
Instance Method Summary collapse
- #at(time) ⇒ Object
- #cron(patterns) ⇒ Object
- #detail(year: nil, month: nil, day: nil, wday: nil, hour: nil, min: nil, sec: 0, msec: nil) ⇒ Object
- #new(at: nil, cron: nil, year: nil, month: nil, day: nil, wday: nil, hour: nil, min: nil, sec: 0, msec: nil) ⇒ Object
Instance Method Details
#at(time) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/time_cursor/base.rb', line 18 def at( time ) case time when String date = Date.parse( time ) rescue nil time = Time.parse( time ) when Time date = time.to_date end case time when Date Matcher.new( year: time.year, month: time.month, day: time.day, hour: 0, min: 0, sec: 0, ) when Time if date.nil? Matcher.new( hour: time.hour, min: time.min, sec: time.sec, ) else Matcher.new( year: time.year, month: time.month, day: time.day, hour: time.hour, min: time.min, sec: time.sec, ) end else raise ArgumentError, "invalid class : '#{datetime}'" end end |
#cron(patterns) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/time_cursor/base.rb', line 59 def cron( patterns ) case patterns when String else raise ArgumentError, "invalid class : '#{patterns}'" end a = patterns.split("\s") unless a.size == 5 raise ArgumentError, "too/few count of fields : '#{patterns}'" end Matcher.new( month: a[3], day: a[2], wday: a[4], hour: a[1], min: a[0], ) end |
#detail(year: nil, month: nil, day: nil, wday: nil, hour: nil, min: nil, sec: 0, msec: nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/time_cursor/base.rb', line 78 def detail( year: nil, month: nil, day: nil, wday: nil, hour: nil, min: nil, sec: 0, msec: nil ) if msec.nil? month ||= 1 unless year.nil? day ||= 1 unless month.nil? hour ||= 0 unless ( day.nil? && wday.nil? ) min ||= 0 unless hour.nil? Matcher.new( year: year, month: month, day: day, wday: wday, hour: hour, min: min, sec: sec, ) else Matcher.new( msec: msec, ) end end |
#new(at: nil, cron: nil, year: nil, month: nil, day: nil, wday: nil, hour: nil, min: nil, sec: 0, msec: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/time_cursor/base.rb', line 8 def new( at: nil, cron: nil, year: nil, month: nil, day: nil, wday: nil, hour: nil, min: nil, sec: 0, msec: nil ) if !at.nil? at( at ) elsif !cron.nil? cron( cron ) else detail( year: year, month: month, day: day, wday: wday, hour: hour, min: min, sec: sec, msec: msec ) end end |