Class: Astronoby::Configuration

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

Constant Summary collapse

DEFAULT_PRECISIONS =
{
  geometric: 9,        # 8.64e-5 seconds
  nutation: 2,         # 864 seconds
  precession: 2,       # 864 seconds
  rise_transit_set: 5  # 0.1 seconds
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



15
16
17
18
19
# File 'lib/astronoby/configuration.rb', line 15

def initialize
  @cache_enabled = false
  @cache_precisions = DEFAULT_PRECISIONS.dup
  @cache_instance = nil
end

Instance Attribute Details

#cache_enabledObject

Returns the value of attribute cache_enabled.



12
13
14
# File 'lib/astronoby/configuration.rb', line 12

def cache_enabled
  @cache_enabled
end

#cache_precisionsObject

Returns the value of attribute cache_precisions.



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

def cache_precisions
  @cache_precisions
end

Instance Method Details

#cacheAstronoby::Cache, Astronoby::NullCache

Get the cache instance (singleton or null cache)

Returns:



43
44
45
46
47
48
49
# File 'lib/astronoby/configuration.rb', line 43

def cache
  if cache_enabled?
    Cache.instance
  else
    NullCache.instance
  end
end

#cache_enabled?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/astronoby/configuration.rb', line 51

def cache_enabled?
  @cache_enabled
end

#cache_precision(type, precision = nil) ⇒ Numeric

Configure cache precision for specific calculation types

Parameters:

  • type (Symbol)

    The calculation type

  • precision (Numeric) (defaults to: nil)

    Precision in rounding of terrestrial time

Returns:

  • (Numeric)

    the precision for the given type



25
26
27
28
29
30
31
# File 'lib/astronoby/configuration.rb', line 25

def cache_precision(type, precision = nil)
  if precision.nil?
    @cache_precisions[type] || DEFAULT_PRECISIONS[:geometric]
  else
    @cache_precisions[type] = precision
  end
end

#reset_cache!void

This method returns an undefined value.

Reset cache instance (useful for testing or configuration changes)



57
58
59
# File 'lib/astronoby/configuration.rb', line 57

def reset_cache!
  cache.clear
end