Class: Mapbox::Base
- Inherits:
-
Object
- Object
- Mapbox::Base
- Extended by:
- Forwardable
- Defined in:
- lib/mapbox/base.rb
Overview
Base class
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#map_option ⇒ Object
Returns the value of attribute map_option.
-
#map_type ⇒ Object
Returns the value of attribute map_type.
-
#mapid ⇒ Object
Returns the value of attribute mapid.
-
#overlays ⇒ Object
Returns the value of attribute overlays.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Instance Method Summary collapse
- #base_url ⇒ Object
- #connection ⇒ Object
-
#initialize(opts = {}) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
-
#llz ⇒ Object
latitude longitude zoom.
- #parameters_check ⇒ Object
-
#wh ⇒ Object
width and height.
Constructor Details
#initialize(opts = {}) {|_self| ... } ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 23 |
# File 'lib/mapbox/base.rb', line 16 def initialize(opts = {}) opts.each do |key, value| instance_variable_set("@#{key}", value) end @overlays ||= [] yield(self) if block_given? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/mapbox/base.rb', line 9 def access_token @access_token end |
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
9 10 11 |
# File 'lib/mapbox/base.rb', line 9 def access_token_secret @access_token_secret end |
#lat ⇒ Object
Returns the value of attribute lat.
12 13 14 |
# File 'lib/mapbox/base.rb', line 12 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
12 13 14 |
# File 'lib/mapbox/base.rb', line 12 def lon @lon end |
#map_option ⇒ Object
Returns the value of attribute map_option.
10 11 12 |
# File 'lib/mapbox/base.rb', line 10 def map_option @map_option end |
#map_type ⇒ Object
Returns the value of attribute map_type.
10 11 12 |
# File 'lib/mapbox/base.rb', line 10 def map_type @map_type end |
#mapid ⇒ Object
Returns the value of attribute mapid.
10 11 12 |
# File 'lib/mapbox/base.rb', line 10 def mapid @mapid end |
#overlays ⇒ Object
Returns the value of attribute overlays.
10 11 12 |
# File 'lib/mapbox/base.rb', line 10 def @overlays end |
#x ⇒ Object
Returns the value of attribute x.
11 12 13 |
# File 'lib/mapbox/base.rb', line 11 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
11 12 13 |
# File 'lib/mapbox/base.rb', line 11 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
11 12 13 |
# File 'lib/mapbox/base.rb', line 11 def z @z end |
#zoom ⇒ Object
Returns the value of attribute zoom.
12 13 14 |
# File 'lib/mapbox/base.rb', line 12 def zoom @zoom end |
Instance Method Details
#base_url ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/mapbox/base.rb', line 30 def base_url = @overlays.join(',') if @overlays.size > 0 ||= nil [API_URL, API_VERSION, @mapid, , @llz, @z, @x, @y, @map_option, @wh] .compact .join('/') + ".#{@map_type}" end |
#connection ⇒ Object
40 41 42 |
# File 'lib/mapbox/base.rb', line 40 def connection Excon.new(base_url, query: { access_token: @access_token }) end |
#llz ⇒ Object
latitude longitude zoom
45 46 47 |
# File 'lib/mapbox/base.rb', line 45 def llz [@lat, @lon, @zoom].join(',') end |
#parameters_check ⇒ Object
25 26 27 28 |
# File 'lib/mapbox/base.rb', line 25 def parameters_check fail ArgumentError, ':access_token' if @access_token.nil? fail ArgumentError, ':mapid' if @mapid.nil? end |
#wh ⇒ Object
width and height
50 51 52 |
# File 'lib/mapbox/base.rb', line 50 def wh [@width, @height].join('x') end |