Module: IERS::Data
- Defined in:
- lib/iers/data.rb
Constant Summary collapse
- FILENAMES =
{ finals: "finals2000A.all", leap_seconds: "Leap_Second.dat" }.freeze
- BUNDLED_DIR =
Pathname(__dir__).join("..", "..", "data").
Class Method Summary collapse
- .clear_cache! ⇒ void
- .clear_loaded! ⇒ void
- .ensure_fresh!(coverage_days_ahead: nil) ⇒ void
- .finals_entries ⇒ Array<Parsers::Finals::Entry>
- .leap_second_entries ⇒ Array<Parsers::LeapSecond::Entry>
- .loaded? ⇒ Boolean
- .status ⇒ DataStatus
- .update!(*sources) ⇒ UpdateResult
Class Method Details
.clear_cache! ⇒ void
This method returns an undefined value.
63 64 65 66 67 68 69 70 |
# File 'lib/iers/data.rb', line 63 def clear_cache! config = IERS.configuration FILENAMES.each_value do |filename| path = config.cache_dir.join(filename) path.delete if path.exist? end end |
.clear_loaded! ⇒ void
This method returns an undefined value.
155 156 157 158 159 160 |
# File 'lib/iers/data.rb', line 155 def clear_loaded! @mutex.synchronize do @finals = nil @leap_seconds = nil end end |
.ensure_fresh!(coverage_days_ahead: nil) ⇒ void
This method returns an undefined value.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/iers/data.rb', line 75 def ensure_fresh!(coverage_days_ahead: nil) predicted_until = finals_entries.last.date required_until = Date.today + (coverage_days_ahead || 0) return if predicted_until >= required_until raise StaleDataError.new( "Predictions only extend to #{predicted_until} " \ "but coverage through #{required_until} is required", predicted_until: predicted_until, required_until: required_until ) end |
.finals_entries ⇒ Array<Parsers::Finals::Entry>
90 91 92 93 94 95 96 97 |
# File 'lib/iers/data.rb', line 90 def finals_entries @mutex.synchronize do @finals ||= begin path = resolve_read_path(:finals) Parsers::Finals.parse(path).freeze end end end |
.leap_second_entries ⇒ Array<Parsers::LeapSecond::Entry>
100 101 102 103 104 105 106 107 |
# File 'lib/iers/data.rb', line 100 def leap_second_entries @mutex.synchronize do @leap_seconds ||= begin path = resolve_read_path(:leap_seconds) Parsers::LeapSecond.parse(path).freeze end end end |
.loaded? ⇒ Boolean
19 20 21 |
# File 'lib/iers/data.rb', line 19 def loaded? !@finals.nil? || !@leap_seconds.nil? end |
.status ⇒ DataStatus
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/iers/data.rb', line 49 def status config = IERS.configuration if custom_paths_configured?(config) DataStatus.new(source: :custom, cache_age: nil) elsif cache_exists?(config) age = oldest_cache_age(config) DataStatus.new(source: :cached, cache_age: age) else DataStatus.new(source: :bundled, cache_age: nil) end end |
.update!(*sources) ⇒ UpdateResult
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/iers/data.rb', line 25 def update!(*sources) config = IERS.configuration sources = config.sources.keys if sources.empty? updated = [] errors = {} sources.each do |source| validate_source!(source, config) url = config.sources[source] dest = resolve_path(source, config) begin Downloader.new(timeout: config.download_timeout).fetch(url, dest) updated << source rescue DownloadError => e errors[source] = e end end UpdateResult.new(updated_files: updated, errors: errors) end |