Class: Astronoby::Center
- Inherits:
-
Object
- Object
- Astronoby::Center
- Defined in:
- lib/astronoby/center.rb
Constant Summary collapse
- BARYCENTRIC =
:barycentric- GEOCENTRIC =
:geocentric- TOPOCENTRIC =
:topocentric
Instance Attribute Summary collapse
-
#kind ⇒ Symbol
readonly
The kind of center.
-
#observer ⇒ Astronoby::Observer?
readonly
The observer, for topocentric centers.
Class Method Summary collapse
-
.barycentric ⇒ Astronoby::Center
The Solar System barycenter.
-
.geocentric ⇒ Astronoby::Center
The Earth’s center.
-
.topocentric(observer) ⇒ Astronoby::Center
A center at the observer’s location.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True if both centers are equivalent.
-
#barycentric? ⇒ Boolean
True if the center is the Solar System barycenter.
-
#geocentric? ⇒ Boolean
True if the center is the Earth’s center.
-
#hash ⇒ Integer
Hash value.
-
#initialize(kind:, observer: nil) ⇒ Center
constructor
A new instance of Center.
-
#observer_dependent? ⇒ Boolean
True if the center depends on a specific observer.
-
#topocentric? ⇒ Boolean
True if the center is at an observer’s location.
Constructor Details
#initialize(kind:, observer: nil) ⇒ Center
Returns a new instance of Center.
35 36 37 38 39 |
# File 'lib/astronoby/center.rb', line 35 def initialize(kind:, observer: nil) @kind = kind @observer = observer freeze end |
Instance Attribute Details
#kind ⇒ Symbol (readonly)
Returns the kind of center.
28 29 30 |
# File 'lib/astronoby/center.rb', line 28 def kind @kind end |
#observer ⇒ Astronoby::Observer? (readonly)
Returns the observer, for topocentric centers.
31 32 33 |
# File 'lib/astronoby/center.rb', line 31 def observer @observer end |
Class Method Details
.barycentric ⇒ Astronoby::Center
Returns the Solar System barycenter.
11 12 13 |
# File 'lib/astronoby/center.rb', line 11 def @barycentric ||= new(kind: BARYCENTRIC) end |
.geocentric ⇒ Astronoby::Center
Returns the Earth’s center.
16 17 18 |
# File 'lib/astronoby/center.rb', line 16 def geocentric @geocentric ||= new(kind: GEOCENTRIC) end |
.topocentric(observer) ⇒ Astronoby::Center
Returns a center at the observer’s location.
22 23 24 |
# File 'lib/astronoby/center.rb', line 22 def topocentric(observer) new(kind: TOPOCENTRIC, observer: observer) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if both centers are equivalent.
63 64 65 66 67 |
# File 'lib/astronoby/center.rb', line 63 def ==(other) other.is_a?(self.class) && kind == other.kind && location_key == other.location_key end |
#barycentric? ⇒ Boolean
Returns true if the center is the Solar System barycenter.
42 43 44 |
# File 'lib/astronoby/center.rb', line 42 def @kind == BARYCENTRIC end |
#geocentric? ⇒ Boolean
Returns true if the center is the Earth’s center.
47 48 49 |
# File 'lib/astronoby/center.rb', line 47 def geocentric? @kind == GEOCENTRIC end |
#hash ⇒ Integer
Returns hash value.
71 72 73 |
# File 'lib/astronoby/center.rb', line 71 def hash [self.class, @kind, location_key].hash end |
#observer_dependent? ⇒ Boolean
Returns true if the center depends on a specific observer.
57 58 59 |
# File 'lib/astronoby/center.rb', line 57 def observer_dependent? topocentric? end |
#topocentric? ⇒ Boolean
Returns true if the center is at an observer’s location.
52 53 54 |
# File 'lib/astronoby/center.rb', line 52 def topocentric? @kind == TOPOCENTRIC end |