Class: Astronoby::SiderealTime
- Inherits:
-
Object
- Object
- Astronoby::SiderealTime
- Defined in:
- lib/astronoby/time/sidereal_time.rb
Overview
Base class for sidereal time representations. Sidereal time measures the rotation of the Earth relative to the vernal equinox.
Direct Known Subclasses
Constant Summary collapse
- TYPES =
[ MEAN = :mean, APPARENT = :apparent ].freeze
Instance Attribute Summary collapse
-
#date ⇒ Date
readonly
The calendar date.
-
#time ⇒ Numeric
readonly
The sidereal time in hours.
-
#type ⇒ Symbol
readonly
:mean or :apparent.
Class Method Summary collapse
-
.normalize_time(time) ⇒ Numeric
Normalizes a time value to the range [0, 24) hours.
- .validate_type!(type) ⇒ Object
Instance Method Summary collapse
-
#apparent? ⇒ Boolean
True if this is apparent sidereal time.
-
#initialize(date:, time:, type: MEAN) ⇒ SiderealTime
constructor
A new instance of SiderealTime.
-
#mean? ⇒ Boolean
True if this is mean sidereal time.
-
#normalize_time(time) ⇒ Numeric
Normalized time in hours.
Constructor Details
#initialize(date:, time:, type: MEAN) ⇒ SiderealTime
Returns a new instance of SiderealTime.
42 43 44 45 46 |
# File 'lib/astronoby/time/sidereal_time.rb', line 42 def initialize(date:, time:, type: MEAN) @date = date @time = time @type = type end |
Instance Attribute Details
#date ⇒ Date (readonly)
Returns the calendar date.
13 14 15 |
# File 'lib/astronoby/time/sidereal_time.rb', line 13 def date @date end |
#time ⇒ Numeric (readonly)
Returns the sidereal time in hours.
16 17 18 |
# File 'lib/astronoby/time/sidereal_time.rb', line 16 def time @time end |
#type ⇒ Symbol (readonly)
Returns :mean or :apparent.
19 20 21 |
# File 'lib/astronoby/time/sidereal_time.rb', line 19 def type @type end |
Class Method Details
.normalize_time(time) ⇒ Numeric
Normalizes a time value to the range [0, 24) hours.
25 26 27 28 29 |
# File 'lib/astronoby/time/sidereal_time.rb', line 25 def self.normalize_time(time) time += Constants::HOURS_PER_DAY if time.negative? time -= Constants::HOURS_PER_DAY if time > Constants::HOURS_PER_DAY time end |
Instance Method Details
#apparent? ⇒ Boolean
Returns true if this is apparent sidereal time.
54 55 56 |
# File 'lib/astronoby/time/sidereal_time.rb', line 54 def apparent? @type == APPARENT end |
#mean? ⇒ Boolean
Returns true if this is mean sidereal time.
49 50 51 |
# File 'lib/astronoby/time/sidereal_time.rb', line 49 def mean? @type == MEAN end |
#normalize_time(time) ⇒ Numeric
Returns normalized time in hours.
60 61 62 |
# File 'lib/astronoby/time/sidereal_time.rb', line 60 def normalize_time(time) self.class.normalize_time(time) end |