Class: Vfrmap

Inherits:
Object
  • Object
show all
Includes:
Padrino::Helpers::TagHelpers
Defined in:
lib/vfrmap.rb,
lib/vfrmap/version.rb

Defined Under Namespace

Classes: Location

Constant Summary collapse

DEFAULT_OPTIONS =
{
  type: 'vfrc',
  zoom: 10,
  width: 350,
  height: 350,
  class: nil,
  alt: nil
}
VERSION =
"1.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location_string, options = {}) ⇒ Vfrmap

Returns a new instance of Vfrmap.



23
24
25
26
27
# File 'lib/vfrmap.rb', line 23

def initialize(location_string,options={})
  @location = Location.factory(location_string)
  raise 'Invalid location' unless @location
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/vfrmap.rb', line 21

def options
  @options
end

Instance Method Details

#to_base64_jpgObject



44
45
46
# File 'lib/vfrmap.rb', line 44

def to_base64_jpg
  Base64.encode64(to_jpg)
end

#to_htmlObject



36
37
38
# File 'lib/vfrmap.rb', line 36

def to_html
  tag(:img, src: src, class: @options[:class], alt: @options[:alt])
end

#to_jpgObject



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

def to_jpg
  open(uri).read
end

#uriObject Also known as: src



29
30
31
32
33
# File 'lib/vfrmap.rb', line 29

def uri
  URI::HTTP
    .build(host: 'vfrmap.com', path: '/api', query: query_params)
    .to_s
end