Class: VORuby::CoordinateSystems::Equatorial::RightAscension
- Defined in:
- lib/voruby/spacetime/spacetime.rb
Constant Summary collapse
- MIN_ALLOWED_VALUE =
0.0
- MAX_ALLOWED_VALUE =
360.0
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.from_sexigesimal(ra) ⇒ Object
Create a RightAscension object from a string in sexigesimal format.
-
.in_range?(ra) ⇒ Boolean
Is the supplied number in the correct range for a right ascension (i.e between 0 and 360 degrees)?.
Instance Method Summary collapse
-
#+(degrees) ⇒ Object
Returns a RightAscension object projected forward the specified number of degrees.
-
#-(degrees) ⇒ Object
Returns a RightAscension object projected backward the specified number of degrees.
- #<=>(ra) ⇒ Object
- #==(ra) ⇒ Object
-
#decrement(degrees) ⇒ Object
Subtract the specified number of degrees from the ra.
-
#increment(degrees) ⇒ Object
Add the specified number of degrees to the ra.
-
#initialize(ra) ⇒ RightAscension
constructor
Create a RightAscenson object.
- #to_s ⇒ Object
-
#to_sexigesimal(sep = ':') ⇒ Object
Return the value of the ra as a string in sexigesimal format.
Constructor Details
#initialize(ra) ⇒ RightAscension
Create a RightAscenson object.
294 295 296 |
# File 'lib/voruby/spacetime/spacetime.rb', line 294 def initialize(ra) self.value = ra end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
288 289 290 |
# File 'lib/voruby/spacetime/spacetime.rb', line 288 def value @value end |
Class Method Details
.from_sexigesimal(ra) ⇒ Object
Create a RightAscension object from a string in sexigesimal format. Numerical values may be separated by a space or colon (but not both).
322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/voruby/spacetime/spacetime.rb', line 322 def self.from_sexigesimal(ra) raise Exception::InvalidSexigesimalFormat.new(ra) if !Equatorial::looks_like_sexigesimal?(ra) hours_s, minutes_s, seconds_s = ra.split(/:|\s+/) hours = hours_s.to_f minutes = minutes_s.to_f seconds = seconds_s.to_f ra_degrees = 15.0 * (hours + (minutes + seconds.to_f / 60.0) / 60.0) return RightAscension.new(ra_degrees) end |
.in_range?(ra) ⇒ Boolean
Is the supplied number in the correct range for a right ascension (i.e between 0 and 360 degrees)?
316 317 318 |
# File 'lib/voruby/spacetime/spacetime.rb', line 316 def self.in_range?(ra) (MIN_ALLOWED_VALUE..MAX_ALLOWED_VALUE) === ra end |
Instance Method Details
#+(degrees) ⇒ Object
Returns a RightAscension object projected forward the specified number of degrees.
347 348 349 350 351 352 |
# File 'lib/voruby/spacetime/spacetime.rb', line 347 def +(degrees) new_degrees = self.value + degrees new_degrees = new_degrees - MAX_ALLOWED_VALUE if new_degrees > MAX_ALLOWED_VALUE RightAscension.new(new_degrees) end |
#-(degrees) ⇒ Object
Returns a RightAscension object projected backward the specified number of degrees.
362 363 364 365 366 367 |
# File 'lib/voruby/spacetime/spacetime.rb', line 362 def -(degrees) new_degrees = self.value - degrees new_degrees = MAX_ALLOWED_VALUE + new_degrees if new_degrees < MIN_ALLOWED_VALUE RightAscension.new(new_degrees) end |
#<=>(ra) ⇒ Object
375 376 377 |
# File 'lib/voruby/spacetime/spacetime.rb', line 375 def <=>(ra) self.value <=> ra.value end |
#==(ra) ⇒ Object
379 380 381 |
# File 'lib/voruby/spacetime/spacetime.rb', line 379 def ==(ra) self.value == ra.value end |
#decrement(degrees) ⇒ Object
Subtract the specified number of degrees from the ra.
370 371 372 373 |
# File 'lib/voruby/spacetime/spacetime.rb', line 370 def decrement(degrees) new_degrees = self - degrees self.value = new_degrees.value end |
#increment(degrees) ⇒ Object
Add the specified number of degrees to the ra.
355 356 357 358 |
# File 'lib/voruby/spacetime/spacetime.rb', line 355 def increment(degrees) new_degrees = self + degrees self.value = new_degrees.value end |
#to_s ⇒ Object
383 384 385 |
# File 'lib/voruby/spacetime/spacetime.rb', line 383 def to_s "#{self.to_sexigesimal}" end |
#to_sexigesimal(sep = ':') ⇒ Object
Return the value of the ra as a string in sexigesimal format.
336 337 338 339 340 341 342 343 |
# File 'lib/voruby/spacetime/spacetime.rb', line 336 def to_sexigesimal(sep=':') rah = (self.value / 15.0).to_i() ram = ((self.value - 15.0 * rah) * (60.0 / 15.0)).to_i() ras = self.value - (rah * 15.0) - (ram / (60.0 / 15.0)) ras = ras * (60.0 * 60.0 / 15.0) return sprintf("%02u#{sep}%02u#{sep}%0.2f", rah, ram, ras) end |