Class: Bandit::DateHour
- Inherits:
-
Object
- Object
- Bandit::DateHour
- Defined in:
- lib/bandit/date_hour.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#hour ⇒ Object
Returns the value of attribute hour.
Class Method Summary collapse
-
.date_inject(date, initial = 0) ⇒ Object
given a block that is called w/ each DateHour for a day, inject over all DateHours.
- .now ⇒ Object
Instance Method Summary collapse
- #+(hours) ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #day ⇒ Object
-
#initialize(date, hour) ⇒ DateHour
constructor
A new instance of DateHour.
- #month ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_time ⇒ Object
- #upto(other) ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(date, hour) ⇒ DateHour
Returns a new instance of DateHour.
8 9 10 11 |
# File 'lib/bandit/date_hour.rb', line 8 def initialize(date, hour) @date = date @hour = hour end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/bandit/date_hour.rb', line 6 def date @date end |
#hour ⇒ Object
Returns the value of attribute hour.
6 7 8 |
# File 'lib/bandit/date_hour.rb', line 6 def hour @hour end |
Class Method Details
.date_inject(date, initial = 0) ⇒ Object
given a block that is called w/ each DateHour for a day, inject over all DateHours
26 27 28 29 30 31 |
# File 'lib/bandit/date_hour.rb', line 26 def self.date_inject(date, initial=0) DateHour.new(date, 0).upto(DateHour.new(date, 23)) { |dh| initial = yield initial, dh } initial end |
Instance Method Details
#+(hours) ⇒ Object
33 34 35 |
# File 'lib/bandit/date_hour.rb', line 33 def +(hours) (to_time + (hours * 3600)).to_date_hour end |
#<(other) ⇒ Object
41 42 43 |
# File 'lib/bandit/date_hour.rb', line 41 def <(other) @date < other.date or (@date == other.date and @hour < other.hour) end |
#<=(other) ⇒ Object
53 54 55 |
# File 'lib/bandit/date_hour.rb', line 53 def <=(other) self < other or self == other end |
#==(other) ⇒ Object
37 38 39 |
# File 'lib/bandit/date_hour.rb', line 37 def ==(other) @date == other.date and @hour == other.hour end |
#>(other) ⇒ Object
45 46 47 |
# File 'lib/bandit/date_hour.rb', line 45 def >(other) @date > other.date or (@date == other.date and @hour > other.hour) end |
#>=(other) ⇒ Object
49 50 51 |
# File 'lib/bandit/date_hour.rb', line 49 def >=(other) self > other or self == other end |
#day ⇒ Object
77 78 79 |
# File 'lib/bandit/date_hour.rb', line 77 def day @date.day end |
#month ⇒ Object
73 74 75 |
# File 'lib/bandit/date_hour.rb', line 73 def month @date.month end |
#to_i ⇒ Object
65 66 67 |
# File 'lib/bandit/date_hour.rb', line 65 def to_i to_time.to_i end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/bandit/date_hour.rb', line 61 def to_s "#{@date.to_s} #{@hour}:00:00" end |
#to_time ⇒ Object
57 58 59 |
# File 'lib/bandit/date_hour.rb', line 57 def to_time Time.mktime year, month, day, hour, 0 end |
#upto(other) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/bandit/date_hour.rb', line 17 def upto(other) n = DateHour.new(@date, @hour) while n <= other yield n n += 1 end end |
#year ⇒ Object
69 70 71 |
# File 'lib/bandit/date_hour.rb', line 69 def year @date.year end |