Class: Tomlrb::LocalTime
- Inherits:
-
Object
- Object
- Tomlrb::LocalTime
- Extended by:
- Forwardable
- Defined in:
- lib/tomlrb/local_time.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(hour, min, sec) ⇒ LocalTime
constructor
A new instance of LocalTime.
- #inspect ⇒ Object
- #to_s ⇒ Object
-
#to_time(year, month, day, offset = '-00:00') ⇒ Time
The time of the date specified by params.
Constructor Details
#initialize(hour, min, sec) ⇒ LocalTime
Returns a new instance of LocalTime.
9 10 11 12 |
# File 'lib/tomlrb/local_time.rb', line 9 def initialize(hour, min, sec) @time = Time.new(0, 1, 1, hour, min, sec, '-00:00') @sec = sec end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 |
# File 'lib/tomlrb/local_time.rb', line 29 def ==(other) other.kind_of?(self.class) && @time == other.to_time(0, 1, 1) end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/tomlrb/local_time.rb', line 34 def inspect "#<#{self.class}: #{to_s}>" end |
#to_s ⇒ Object
23 24 25 26 27 |
# File 'lib/tomlrb/local_time.rb', line 23 def to_s frac = (@sec - sec) frac_str = frac == 0 ? '' : "#{frac.to_s[1..-1]}" @time.strftime("%T") << frac_str end |
#to_time(year, month, day, offset = '-00:00') ⇒ Time
Returns the time of the date specified by params.
19 20 21 |
# File 'lib/tomlrb/local_time.rb', line 19 def to_time(year, month, day, offset='-00:00') Time.new(year, month, day, hour, min, @sec, offset) end |