Class: Mapbox::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mapbox/base.rb

Overview

Base class

Direct Known Subclasses

Html, Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:

  • _self (Mapbox::Base)

    the object that the method was called on



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_tokenObject

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_secretObject

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

#latObject

Returns the value of attribute lat.



12
13
14
# File 'lib/mapbox/base.rb', line 12

def lat
  @lat
end

#lonObject

Returns the value of attribute lon.



12
13
14
# File 'lib/mapbox/base.rb', line 12

def lon
  @lon
end

#map_optionObject

Returns the value of attribute map_option.



10
11
12
# File 'lib/mapbox/base.rb', line 10

def map_option
  @map_option
end

#map_typeObject

Returns the value of attribute map_type.



10
11
12
# File 'lib/mapbox/base.rb', line 10

def map_type
  @map_type
end

#mapidObject

Returns the value of attribute mapid.



10
11
12
# File 'lib/mapbox/base.rb', line 10

def mapid
  @mapid
end

#overlaysObject

Returns the value of attribute overlays.



10
11
12
# File 'lib/mapbox/base.rb', line 10

def overlays
  @overlays
end

#xObject

Returns the value of attribute x.



11
12
13
# File 'lib/mapbox/base.rb', line 11

def x
  @x
end

#yObject

Returns the value of attribute y.



11
12
13
# File 'lib/mapbox/base.rb', line 11

def y
  @y
end

#zObject

Returns the value of attribute z.



11
12
13
# File 'lib/mapbox/base.rb', line 11

def z
  @z
end

#zoomObject

Returns the value of attribute zoom.



12
13
14
# File 'lib/mapbox/base.rb', line 12

def zoom
  @zoom
end

Instance Method Details

#base_urlObject



30
31
32
33
34
35
36
37
38
# File 'lib/mapbox/base.rb', line 30

def base_url
  tmp_overlays = @overlays.join(',') if @overlays.size > 0
  tmp_overlays ||= nil

  [API_URL, API_VERSION, @mapid, tmp_overlays,
   @llz, @z, @x, @y, @map_option, @wh]
    .compact
    .join('/') + ".#{@map_type}"
end

#connectionObject



40
41
42
# File 'lib/mapbox/base.rb', line 40

def connection
  Excon.new(base_url, query: { access_token: @access_token })
end

#llzObject

latitude longitude zoom



45
46
47
# File 'lib/mapbox/base.rb', line 45

def llz
  [@lat, @lon, @zoom].join(',')
end

#parameters_checkObject



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

#whObject

width and height



50
51
52
# File 'lib/mapbox/base.rb', line 50

def wh
  [@width, @height].join('x')
end