Class: Biz::DayTime
- Inherits:
-
Object
- Object
- Biz::DayTime
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/biz/day_time.rb
Defined Under Namespace
Modules: Timestamp
Instance Attribute Summary collapse
-
#day_second ⇒ Object
readonly
Returns the value of attribute day_second.
Class Method Summary collapse
- .endnight ⇒ Object
- .from_hour(hour) ⇒ Object
- .from_minute(minute) ⇒ Object
- .from_time(time) ⇒ Object
- .from_timestamp(timestamp) ⇒ Object
- .midnight ⇒ Object (also: am)
- .noon ⇒ Object (also: pm)
Instance Method Summary collapse
- #coerce(other) ⇒ Object
- #day_minute ⇒ Object
- #hour ⇒ Object
-
#initialize(day_second) ⇒ DayTime
constructor
A new instance of DayTime.
- #minute ⇒ Object
- #second ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(day_second) ⇒ DayTime
Returns a new instance of DayTime.
66 67 68 |
# File 'lib/biz/day_time.rb', line 66 def initialize(day_second) @day_second = Integer(day_second) end |
Instance Attribute Details
#day_second ⇒ Object (readonly)
Returns the value of attribute day_second.
57 58 59 |
# File 'lib/biz/day_time.rb', line 57 def day_second @day_second end |
Class Method Details
.endnight ⇒ Object
51 52 53 |
# File 'lib/biz/day_time.rb', line 51 def endnight ENDNIGHT end |
.from_hour(hour) ⇒ Object
25 26 27 |
# File 'lib/biz/day_time.rb', line 25 def from_hour(hour) new(hour * Time::HOUR) end |
.from_minute(minute) ⇒ Object
21 22 23 |
# File 'lib/biz/day_time.rb', line 21 def from_minute(minute) new(minute * Time::MINUTE) end |
.from_time(time) ⇒ Object
17 18 19 |
# File 'lib/biz/day_time.rb', line 17 def from_time(time) new(time.hour * Time::HOUR + time.min * Time::MINUTE + time.sec) end |
.from_timestamp(timestamp) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/biz/day_time.rb', line 29 def () .match(Timestamp::PATTERN) { |match| new( match[:hour].to_i * Time::HOUR + match[:minute].to_i * Time::MINUTE + match[:second].to_i ) } end |
.midnight ⇒ Object Also known as: am
39 40 41 |
# File 'lib/biz/day_time.rb', line 39 def midnight MIDNIGHT end |
.noon ⇒ Object Also known as: pm
45 46 47 |
# File 'lib/biz/day_time.rb', line 45 def noon NOON end |
Instance Method Details
#coerce(other) ⇒ Object
90 91 92 |
# File 'lib/biz/day_time.rb', line 90 def coerce(other) [self.class.new(other), self] end |
#day_minute ⇒ Object
82 83 84 |
# File 'lib/biz/day_time.rb', line 82 def day_minute hour * Time::MINUTES_IN_HOUR + minute end |
#minute ⇒ Object
74 75 76 |
# File 'lib/biz/day_time.rb', line 74 def minute day_second % Time::HOUR / Time::MINUTE end |