Class: Astronoby::Hms

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/angles/hms.rb

Overview

Represents an angle in hours, minutes, seconds (HMS) notation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hours, minutes, seconds) ⇒ Hms

Returns a new instance of Hms.

Parameters:

  • hours (Integer)

    hours component

  • minutes (Integer)

    minutes component

  • seconds (Float)

    seconds component



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

#hoursInteger (readonly)

Returns hours component.

Returns:

  • (Integer)

    hours component



7
8
9
# File 'lib/astronoby/angles/hms.rb', line 7

def hours
  @hours
end

#minutesInteger (readonly)

Returns minutes component.

Returns:

  • (Integer)

    minutes component



10
11
12
# File 'lib/astronoby/angles/hms.rb', line 10

def minutes
  @minutes
end

#secondsFloat (readonly)

Returns seconds component.

Returns:

  • (Float)

    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”).

Parameters:

  • precision (Integer) (defaults to: 4)

    decimal places for the seconds component

Returns:

  • (String)

    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