Class: Astronoby::Hms
- Inherits:
-
Object
- Object
- Astronoby::Hms
- Defined in:
- lib/astronoby/angles/hms.rb
Overview
Represents an angle in hours, minutes, seconds (HMS) notation.
Instance Attribute Summary collapse
-
#hours ⇒ Integer
readonly
Hours component.
-
#minutes ⇒ Integer
readonly
Minutes component.
-
#seconds ⇒ Float
readonly
Seconds component.
Instance Method Summary collapse
-
#format(precision: 4) ⇒ String
The formatted HMS string (e.g., “12h 30m 45.0000s”).
-
#initialize(hours, minutes, seconds) ⇒ Hms
constructor
A new instance of Hms.
Constructor Details
#initialize(hours, minutes, seconds) ⇒ Hms
Returns a new instance of Hms.
18 19 20 21 22 |
# File 'lib/astronoby/angles/hms.rb', line 18 def initialize(hours, minutes, seconds) @hours = hours @minutes = minutes @seconds = seconds end |
Instance Attribute Details
#hours ⇒ Integer (readonly)
Returns hours component.
7 8 9 |
# File 'lib/astronoby/angles/hms.rb', line 7 def hours @hours end |
#minutes ⇒ Integer (readonly)
Returns minutes component.
10 11 12 |
# File 'lib/astronoby/angles/hms.rb', line 10 def minutes @minutes end |
#seconds ⇒ Float (readonly)
Returns seconds component.
13 14 15 |
# File 'lib/astronoby/angles/hms.rb', line 13 def seconds @seconds end |
Instance Method Details
#format(precision: 4) ⇒ String
Returns the formatted HMS string (e.g., “12h 30m 45.0000s”).
26 27 28 |
# File 'lib/astronoby/angles/hms.rb', line 26 def format(precision: 4) "#{hours}h #{minutes}m #{seconds.floor(precision)}s" end |