Class: VORuby::CoordinateSystems::Equatorial::Declination
- Defined in:
- lib/voruby/spacetime/spacetime.rb
Constant Summary collapse
- MIN_ALLOWED_VALUE =
-90.0
- MAX_ALLOWED_VALUE =
90.0
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.from_sexigesimal(dec) ⇒ Object
Create a Declination object from a string in sexigesimal format.
-
.in_range?(dec) ⇒ Boolean
Is the supplied number in the correct range for a declination (i.e between -90 and 90 degrees)?.
Instance Method Summary collapse
-
#+(degrees) ⇒ Object
Returns a declination object projected forward the specified number of degrees.
-
#-(degrees) ⇒ Object
Returns a declination object projected backwards the specified number of degrees.
- #<=>(dec) ⇒ Object
- #==(dec) ⇒ Object
-
#decrement(degrees) ⇒ Object
Subtract the specified number of degrees from the dec.
-
#increment(degrees) ⇒ Object
Add the specified number of degrees to the dec.
-
#initialize(dec) ⇒ Declination
constructor
Create a Declination object from a decimal number.
- #to_s ⇒ Object
-
#to_sexigesimal(sep = ':') ⇒ Object
Return the value of the dec as a string in sexigesimal format.
Constructor Details
#initialize(dec) ⇒ Declination
Create a Declination object from a decimal number.
395 396 397 |
# File 'lib/voruby/spacetime/spacetime.rb', line 395 def initialize(dec) self.value = dec end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
389 390 391 |
# File 'lib/voruby/spacetime/spacetime.rb', line 389 def value @value end |
Class Method Details
.from_sexigesimal(dec) ⇒ Object
Create a Declination object from a string in sexigesimal format. Numerical values may be separated by a space or colon (but not both).
423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/voruby/spacetime/spacetime.rb', line 423 def self.from_sexigesimal(dec) raise Exception::InvalidSexigesimalFormat.new(dec) if !Equatorial::looks_like_sexigesimal?(dec) degree, arcmin, arcsec = dec.split(/:|\s+/) degree_f = degree.to_f() arcmin_f = (arcmin.to_f() / 60.0) arcsec_f = (arcsec.to_f() / (60.0 * 60.0)) return Declination.new(degree_f - arcmin_f - arcsec_f) if degree_f < 0 return Declination.new(degree_f + arcmin_f + arcsec_f) end |
.in_range?(dec) ⇒ Boolean
Is the supplied number in the correct range for a declination (i.e between -90 and 90 degrees)?
417 418 419 |
# File 'lib/voruby/spacetime/spacetime.rb', line 417 def self.in_range?(dec) (MIN_ALLOWED_VALUE..MAX_ALLOWED_VALUE) === dec end |
Instance Method Details
#+(degrees) ⇒ Object
Returns a declination object projected forward the specified number of degrees. Note that if the new object will have a value greater than 90 degrees, the declination will be assumed to be exactly 90 degrees, and similarly for -90 degrees.
455 456 457 458 459 460 461 |
# File 'lib/voruby/spacetime/spacetime.rb', line 455 def +(degrees) new_degrees = self.value + degrees new_degrees = MAX_ALLOWED_VALUE if new_degrees > MAX_ALLOWED_VALUE new_degrees = MIN_ALLOWED_VALUE if new_degrees < MIN_ALLOWED_VALUE Declination.new(new_degrees) end |
#-(degrees) ⇒ Object
Returns a declination object projected backwards the specified number of degrees. Note that if the new object will have a value greater less than -90 degrees, the declination will be assumed to be exactly -90 degrees.
473 474 475 476 477 478 |
# File 'lib/voruby/spacetime/spacetime.rb', line 473 def -(degrees) new_degrees = self.value - degrees new_degrees = MIN_ALLOWED_VALUE if new_degrees < MIN_ALLOWED_VALUE Declination.new(new_degrees) end |
#<=>(dec) ⇒ Object
486 487 488 |
# File 'lib/voruby/spacetime/spacetime.rb', line 486 def <=>(dec) self.value <=> dec.value end |
#==(dec) ⇒ Object
490 491 492 |
# File 'lib/voruby/spacetime/spacetime.rb', line 490 def ==(dec) self.value == dec.value end |
#decrement(degrees) ⇒ Object
Subtract the specified number of degrees from the dec.
481 482 483 484 |
# File 'lib/voruby/spacetime/spacetime.rb', line 481 def decrement(degrees) new_degrees = self - degrees self.value = new_degrees.value end |
#increment(degrees) ⇒ Object
Add the specified number of degrees to the dec.
464 465 466 467 |
# File 'lib/voruby/spacetime/spacetime.rb', line 464 def increment(degrees) new_degrees = self + degrees self.value = new_degrees.value end |
#to_s ⇒ Object
494 495 496 |
# File 'lib/voruby/spacetime/spacetime.rb', line 494 def to_s "#{self.to_sexigesimal}" end |
#to_sexigesimal(sep = ':') ⇒ Object
Return the value of the dec as a string in sexigesimal format.
436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/voruby/spacetime/spacetime.rb', line 436 def to_sexigesimal(sep=':') degrees = self.value decsign = '+' if degrees < 0 decsign = '-' degrees = -degrees end decd = degrees.to_i() decm = ((degrees - decd) * 60.0).to_i() decs = degrees - decd - (decm / 60.0) decs = decs * 60.0 * 60.0 return sprintf("%s%02u#{sep}%02u#{sep}%0.2f", decsign, decd, decm, decs) end |