Class: Astronoby::Center

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

Constant Summary collapse

BARYCENTRIC =
:barycentric
GEOCENTRIC =
:geocentric
TOPOCENTRIC =
:topocentric

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, observer: nil) ⇒ Center

Returns a new instance of Center.

Parameters:

  • kind (Symbol)

    one of BARYCENTRIC, GEOCENTRIC, TOPOCENTRIC

  • observer (Astronoby::Observer, nil) (defaults to: nil)

    the observer, for topocentric



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

#kindSymbol (readonly)

Returns the kind of center.

Returns:

  • (Symbol)

    the kind of center



28
29
30
# File 'lib/astronoby/center.rb', line 28

def kind
  @kind
end

#observerAstronoby::Observer? (readonly)

Returns the observer, for topocentric centers.

Returns:



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

def observer
  @observer
end

Class Method Details

.barycentricAstronoby::Center

Returns the Solar System barycenter.

Returns:



11
12
13
# File 'lib/astronoby/center.rb', line 11

def barycentric
  @barycentric ||= new(kind: BARYCENTRIC)
end

.geocentricAstronoby::Center

Returns the Earth’s center.

Returns:



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.

Parameters:

Returns:



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.

Parameters:

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true if the center is the Solar System barycenter



42
43
44
# File 'lib/astronoby/center.rb', line 42

def barycentric?
  @kind == BARYCENTRIC
end

#geocentric?Boolean

Returns true if the center is the Earth’s center.

Returns:

  • (Boolean)

    true if the center is the Earth’s center



47
48
49
# File 'lib/astronoby/center.rb', line 47

def geocentric?
  @kind == GEOCENTRIC
end

#hashInteger

Returns hash value.

Returns:

  • (Integer)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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