Module: Gistance::Configuration

Included in:
Gistance
Defined in:
lib/gistance/configuration.rb

Overview

Methods for Gistance configuration

Constant Summary collapse

VALID_OPTIONS =

Configurable options

[
  :api_endpoint,
  :api_key,
  :language,
  :units,
  :sensor,
  :business
].freeze
DEFAULT_API_ENDPOINT =

Default Google Distance Matrix API endpoint

'https://maps.googleapis.com/maps/api/distancematrix/json'

Instance Method Summary collapse

Instance Method Details

#configure {|_self| ... } ⇒ Object

Set configuration options using a block

Yields:

  • (_self)

Yield Parameters:



25
26
27
# File 'lib/gistance/configuration.rb', line 25

def configure
  yield self
end

#initialize_default_optionsObject

Initialize default options



35
36
37
38
39
40
41
42
# File 'lib/gistance/configuration.rb', line 35

def initialize_default_options
  self.api_endpoint = DEFAULT_API_ENDPOINT
  self.api_key = nil
  self.language = 'en'
  self.units = 'metric'
  self.sensor = false
  self.business = nil
end

#optionsObject

Default options



30
31
32
# File 'lib/gistance/configuration.rb', line 30

def options
  VALID_OPTIONS.inject({}){ |o, k| o.merge!(k => send(k)) }
end

#reset!Object

Reset configuration options to default values



45
46
47
48
49
# File 'lib/gistance/configuration.rb', line 45

def reset!
  initialize_default_options

  self
end