Class: Astronoby::SiderealTime

Inherits:
Object
  • Object
show all
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

GreenwichSiderealTime, LocalSiderealTime

Constant Summary collapse

TYPES =
[
  MEAN = :mean,
  APPARENT = :apparent
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:, time:, type: MEAN) ⇒ SiderealTime

Returns a new instance of SiderealTime.

Parameters:

  • date (Date)

    the calendar date

  • time (Numeric)

    the sidereal time in hours

  • type (Symbol) (defaults to: MEAN)

    :mean or :apparent



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

#dateDate (readonly)

Returns the calendar date.

Returns:

  • (Date)

    the calendar date



13
14
15
# File 'lib/astronoby/time/sidereal_time.rb', line 13

def date
  @date
end

#timeNumeric (readonly)

Returns the sidereal time in hours.

Returns:

  • (Numeric)

    the sidereal time in hours



16
17
18
# File 'lib/astronoby/time/sidereal_time.rb', line 16

def time
  @time
end

#typeSymbol (readonly)

Returns :mean or :apparent.

Returns:

  • (Symbol)

    :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.

Parameters:

  • time (Numeric)

    time in hours

Returns:

  • (Numeric)

    normalized time in 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

.validate_type!(type) ⇒ Object

Parameters:

  • type (Symbol)

    :mean or :apparent

Raises:

  • (ArgumentError)

    if type is invalid



33
34
35
36
37
# File 'lib/astronoby/time/sidereal_time.rb', line 33

def self.validate_type!(type)
  unless TYPES.include?(type)
    raise ArgumentError, "Invalid type: #{type}. Must be one of #{TYPES}"
  end
end

Instance Method Details

#apparent?Boolean

Returns true if this is apparent sidereal time.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • time (Numeric)

    time in hours

Returns:

  • (Numeric)

    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