Class: Ephem::Segments::BaseSegment
- Inherits:
-
Object
- Object
- Ephem::Segments::BaseSegment
- Includes:
- Core::CalendarCalculations, Core::Constants
- Defined in:
- lib/ephem/segments/base_segment.rb
Direct Known Subclasses
Constant Summary collapse
- TARGET_NAMES =
{ Bodies::SOLAR_SYSTEM_BARYCENTER => "Solar System Barycenter", Bodies::MERCURY_BARYCENTER => "Mercury Barycenter", Bodies::VENUS_BARYCENTER => "Venus Barycenter", Bodies::EARTH_MOON_BARYCENTER => "Earth-Moon Barycenter", Bodies::MARS_BARYCENTER => "Mars Barycenter", Bodies::JUPITER_BARYCENTER => "Jupiter Barycenter", Bodies::SATURN_BARYCENTER => "Saturn Barycenter", Bodies::URANUS_BARYCENTER => "Uranus Barycenter", Bodies::NEPTUNE_BARYCENTER => "Neptune Barycenter", Bodies::PLUTO_BARYCENTER => "Pluto Barycenter", Bodies::SUN => "Sun", Bodies::MERCURY => "Mercury", Bodies::VENUS => "Venus", Bodies::MOON => "Moon", Bodies::EARTH => "Earth", Bodies::MARS => "Mars", Bodies::JUPITER => "Jupiter", Bodies::SATURN => "Saturn", Bodies::URANUS => "Uranus", Bodies::NEPTUNE => "Neptune", Bodies::PLUTO => "Pluto" }.freeze
Instance Attribute Summary collapse
-
#center ⇒ Integer
readonly
The center body ID.
-
#daf ⇒ Ephem::IO::DAF
readonly
The DAF object representing the data file.
-
#end_jd ⇒ Float
readonly
End of coverage as a Julian Date.
-
#source ⇒ String
readonly
The source of the segment.
-
#start_jd ⇒ Float
readonly
Start of coverage as a Julian Date.
-
#target ⇒ Integer
readonly
The target body ID.
Instance Method Summary collapse
- #clear_data ⇒ Object
- #compute(_tdb, _tdb2 = 0.0) ⇒ Object
- #compute_and_differentiate(_tdb, _tdb2 = 0.0) ⇒ Object
-
#covers?(tdb, tdb2 = 0.0) ⇒ Boolean
Whether the given time falls within this segment’s coverage.
-
#describe(verbose: false) ⇒ String
Detailed description of the segment.
-
#initialize(daf:, source:, descriptor:) ⇒ BaseSegment
constructor
Initialize a new segment.
-
#to_s ⇒ String
String representation of the segment.
Methods included from Core::CalendarCalculations
format_date, julian_to_gregorian
Constructor Details
#initialize(daf:, source:, descriptor:) ⇒ BaseSegment
Initialize a new segment
59 60 61 62 63 64 65 |
# File 'lib/ephem/segments/base_segment.rb', line 59 def initialize(daf:, source:, descriptor:) @daf = daf @source = source parse_descriptor(descriptor) @start_jd = compute_julian_date(@start_second) @end_jd = compute_julian_date(@end_second) end |
Instance Attribute Details
#center ⇒ Integer (readonly)
Returns the center body ID.
38 39 40 |
# File 'lib/ephem/segments/base_segment.rb', line 38 def center @center end |
#daf ⇒ Ephem::IO::DAF (readonly)
Returns the DAF object representing the data file.
34 35 36 |
# File 'lib/ephem/segments/base_segment.rb', line 34 def daf @daf end |
#end_jd ⇒ Float (readonly)
Returns end of coverage as a Julian Date.
44 45 46 |
# File 'lib/ephem/segments/base_segment.rb', line 44 def end_jd @end_jd end |
#source ⇒ String (readonly)
Returns the source of the segment.
40 41 42 |
# File 'lib/ephem/segments/base_segment.rb', line 40 def source @source end |
#start_jd ⇒ Float (readonly)
Returns start of coverage as a Julian Date.
42 43 44 |
# File 'lib/ephem/segments/base_segment.rb', line 42 def start_jd @start_jd end |
#target ⇒ Integer (readonly)
Returns the target body ID.
36 37 38 |
# File 'lib/ephem/segments/base_segment.rb', line 36 def target @target end |
Instance Method Details
#clear_data ⇒ Object
116 117 118 |
# File 'lib/ephem/segments/base_segment.rb', line 116 def clear_data # Placeholder method to clear any cached data end |
#compute(_tdb, _tdb2 = 0.0) ⇒ Object
106 107 108 109 |
# File 'lib/ephem/segments/base_segment.rb', line 106 def compute(_tdb, _tdb2 = 0.0) raise NotImplementedError, "#{self.class} has not implemented compute() for data type #{@data_type}" end |
#compute_and_differentiate(_tdb, _tdb2 = 0.0) ⇒ Object
111 112 113 114 |
# File 'lib/ephem/segments/base_segment.rb', line 111 def compute_and_differentiate(_tdb, _tdb2 = 0.0) raise NotImplementedError, "#{self.class} has not implemented compute_and_differentiate() for data type #{@data_type}" end |
#covers?(tdb, tdb2 = 0.0) ⇒ Boolean
Whether the given time falls within this segment’s coverage.
102 103 104 |
# File 'lib/ephem/segments/base_segment.rb', line 102 def covers?(tdb, tdb2 = 0.0) (tdb + tdb2).between?(@start_jd, @end_jd) end |
#describe(verbose: false) ⇒ String
Detailed description of the segment
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ephem/segments/base_segment.rb', line 78 def describe(verbose: false) start_date = format_date(*julian_to_gregorian(@start_jd)) end_date = format_date(*julian_to_gregorian(@end_jd)) center_name = get_body_name(@center, "Unknown Center") target_name = get_body_name(@target, "Unknown Target") dates = "#{start_date}..#{end_date}" center = "#{center_name} (#{@center})" target = "#{target_name} (#{@target})" description = "#{dates} Type #{@data_type} #{center} -> #{target}" return description unless verbose <<~DESCRIPTION.chomp #{description} frame=#{@frame} source=#{@source} DESCRIPTION end |
#to_s ⇒ String
String representation of the segment
70 71 72 |
# File 'lib/ephem/segments/base_segment.rb', line 70 def to_s describe(verbose: false) end |