class Navigator

Attributes

location[R]

Public Class Methods

new(location, options = {}) click to toggle source
# File lib/meteorologist/navigator.rb, line 2
def initialize(location, options = {})
  @location = location
  @location_cache_class = options.fetch(:location_cache) { LocationCache }
  @locator_class = options.fetch(:locator) { Locator }
  fetch_cache_values
end

Public Instance Methods

coordinates() click to toggle source
# File lib/meteorologist/navigator.rb, line 9
def coordinates
  @coordinates ||= locator.coordinates
end
location_name() click to toggle source
# File lib/meteorologist/navigator.rb, line 13
def location_name
  @location_name ||= locator.name
end

Private Instance Methods

cached_location() click to toggle source
# File lib/meteorologist/navigator.rb, line 36
def cached_location
  @cached_location ||= @location_cache_class.new(location)
end
fetch_cache_values() click to toggle source
# File lib/meteorologist/navigator.rb, line 20
def fetch_cache_values
  #todo more elegant solution for when cache is not set?
  return unless ENV['CACHE_PATH']

  if cached_location.exists?
    @coordinates = cached_location.coordinates
    @location_name = cached_location.name
  else
    locator.write_to_cache
  end
end
locator() click to toggle source
# File lib/meteorologist/navigator.rb, line 32
def locator
  @locator ||= @locator_class.new(location, cache_class: @location_cache_class)
end