Class: Astronoby::Dms

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

Overview

Represents an angle in degrees, arcminutes, arcseconds (DMS) notation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sign, degrees, minutes, seconds) ⇒ Dms

Returns a new instance of Dms.

Parameters:

  • sign (String)

    “+” or “-”

  • degrees (Integer)

    degrees component

  • minutes (Integer)

    arcminutes component

  • seconds (Float)

    arcseconds component



22
23
24
25
26
27
# File 'lib/astronoby/angles/dms.rb', line 22

def initialize(sign, degrees, minutes, seconds)
  @sign = sign
  @degrees = degrees
  @minutes = minutes
  @seconds = seconds
end

Instance Attribute Details

#degreesInteger (readonly)

Returns degrees component.

Returns:

  • (Integer)

    degrees component



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

def degrees
  @degrees
end

#minutesInteger (readonly)

Returns arcminutes component.

Returns:

  • (Integer)

    arcminutes component



13
14
15
# File 'lib/astronoby/angles/dms.rb', line 13

def minutes
  @minutes
end

#secondsFloat (readonly)

Returns arcseconds component.

Returns:

  • (Float)

    arcseconds component



16
17
18
# File 'lib/astronoby/angles/dms.rb', line 16

def seconds
  @seconds
end

#signString (readonly)

Returns “+” or “-”.

Returns:

  • (String)

    “+” or “-”



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

def sign
  @sign
end

Instance Method Details

#format(precision: 4) ⇒ String

Returns the formatted DMS string (e.g., “+45° 30′ 15.0000″”).

Parameters:

  • precision (Integer) (defaults to: 4)

    decimal places for the seconds component

Returns:

  • (String)

    the formatted DMS string (e.g., “+45° 30′ 15.0000″”)



31
32
33
# File 'lib/astronoby/angles/dms.rb', line 31

def format(precision: 4)
  "#{sign}#{degrees}° #{minutes}#{seconds.floor(precision)}"
end