class Vfrmap

Constants

DEFAULT_OPTIONS
VERSION

Attributes

options[RW]

Public Class Methods

new(location_string,options={}) click to toggle source
# 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

Public Instance Methods

src()
Alias for: uri
to_base64_jpg() click to toggle source
# File lib/vfrmap.rb, line 44
def to_base64_jpg
  Base64.encode64(to_jpg)
end
to_html() click to toggle source
# File lib/vfrmap.rb, line 36
def to_html
  tag(:img, src: src, class: @options[:class], alt: @options[:alt])
end
to_jpg() click to toggle source
# File lib/vfrmap.rb, line 40
def to_jpg
  open(uri).read
end
uri() click to toggle source
# File lib/vfrmap.rb, line 29
def uri
  URI::HTTP
    .build(host: 'vfrmap.com', path: '/api', query: query_params)
    .to_s
end
Also aliased as: src

Private Instance Methods

latitude() click to toggle source
# File lib/vfrmap.rb, line 54
def latitude
  case
  when @location.is_a?(Geo::Coord)
    (@location.to_h[:lat]*10000000).round / 10000000.0
  when @location.is_a?(Airports::Airport)
    @location.latitude.to_f
  end
end
location() click to toggle source
# File lib/vfrmap.rb, line 50
def location
  @location
end
longitude() click to toggle source
# File lib/vfrmap.rb, line 63
def longitude
  case
  when @location.is_a?(Geo::Coord)
    (@location.to_h[:lng]*10000000).round / 10000000.0
  when @location.is_a?(Airports::Airport)
    @location.longitude.to_f
  end
end
query_params() click to toggle source
# File lib/vfrmap.rb, line 72
def query_params
  uri = Addressable::URI.new
  uri.query_values = {
    req:    'map',
    type:   @options[:type],
    lat:    latitude,
    lon:    longitude,
    zoom:   @options[:zoom],
    width:  @options[:width],
    height: @options[:height]
  }
  uri.query
end