class Tankerkoenig::Station
Attributes
brand[R]
house_number[R]
id[R]
is_open[R]
lat[R]
lng[R]
name[R]
opening_times[R]
overrides[R]
place[R]
post_code[R]
price[R]
state[R]
street[R]
whole_day[R]
Public Class Methods
conn()
click to toggle source
# File lib/tankerkoenig/station.rb, line 76 def self.conn Tankerkoenig.conn end
detail(id)
click to toggle source
# File lib/tankerkoenig/station.rb, line 36 def self.detail(id) return Response.new(message: 'you have to submit a valid station id') if id.nil? || id.empty? response = conn.get('detail.php', id: id) attributes = JSON.parse(response.body, symbolize_names: true) response = Response.new(attributes) response.result = Station.new(attributes[:station]) response end
list(lat: nil, lng: nil, rad: 1, type: nil, sort: nil)
click to toggle source
# File lib/tankerkoenig/station.rb, line 46 def self.list(lat: nil, lng: nil, rad: 1, type: nil, sort: nil) type_options = %w[e5 e10 diesel all] sort_options = %w[price dist] return Response.new(message: 'you need to submit a valid lat coordinate') if lat.nil? return Response.new(message: 'you need to submit a valid lng coordinate') if lng.nil? return Response.new(message: 'you need to submit a valid radius between 1 and 25') if rad.nil? || rad.to_f >= 25 || rad.to_f < 1 if sort.nil? && type.nil? type = :all else return Response.new(message: "wrong type parameter. The available options are #{type_options}") unless type_options.include?(type.to_s) end return Response.new(message: "wrong sort parameter. The available options are #{sort_options}") unless sort_options.include?(sort.to_s) response = conn.get('list.php', lat: lat, lng: lng, rad: rad, type: type, sort: sort) attributes = JSON.parse(response.body, symbolize_names: true) response = Response.new(attributes) response.result = [] if response.success? attributes[:stations].each do |station| response.result << Station.new(station) end end response end
new(station)
click to toggle source
# File lib/tankerkoenig/station.rb, line 10 def initialize(station) return if station.nil? @id = station[:id] @name = station[:name] @brand = station[:brand] @street = station[:street] @house_humber = station[:houseNumber] @post_code = station[:postCode] @place = station[:place] @opening_times = [] @overrides = station[:overrides] @whole_day = station[:wholeDay] @is_open = station[:isOpen] @lat = station[:lat] @lng = station[:lng] @state = station[:state] @price = Price.new(@id, station[:e5], station[:e10], station[:diesel], @is_open) open_times = station[:openingTimes] || [] open_times.each do |opening_time| @opening_times << OpeningTime.new(opening_time) end end
Public Instance Methods
closed?()
click to toggle source
# File lib/tankerkoenig/station.rb, line 88 def closed? !@is_open end
detail()
click to toggle source
# File lib/tankerkoenig/station.rb, line 80 def detail Station.detail(@id).result end
diesel()
click to toggle source
# File lib/tankerkoenig/station.rb, line 104 def diesel @price.diesel end
diesel?()
click to toggle source
# File lib/tankerkoenig/station.rb, line 116 def diesel? !diesel.nil? && diesel.class == Float end
e10()
click to toggle source
# File lib/tankerkoenig/station.rb, line 100 def e10 @price.e10 end
e10?()
click to toggle source
# File lib/tankerkoenig/station.rb, line 112 def e10? !e10.nil? && e10.class == Float end
e5()
click to toggle source
# File lib/tankerkoenig/station.rb, line 96 def e5 @price.e5 end
e5?()
click to toggle source
# File lib/tankerkoenig/station.rb, line 108 def e5? !e5.nil? && e5.class == Float end
open?()
click to toggle source
# File lib/tankerkoenig/station.rb, line 84 def open? @is_open end
whole_day?()
click to toggle source
# File lib/tankerkoenig/station.rb, line 92 def whole_day? @whole_day end