Class: Spritpreisrechner::Station
- Inherits:
-
Object
- Object
- Spritpreisrechner::Station
- Defined in:
- lib/spritpreisrechner/station.rb
Constant Summary collapse
- FUEL_TYPES =
%w[DIE SUP GAS].freeze
- REGION_TYPES =
%w[BL PB].freeze
Instance Attribute Summary collapse
-
#contact ⇒ Object
readonly
Returns the value of attribute contact.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#offer_information ⇒ Object
readonly
Returns the value of attribute offer_information.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
-
#opening_hours ⇒ Object
readonly
Returns the value of attribute opening_hours.
-
#other_service_offers ⇒ Object
readonly
Returns the value of attribute other_service_offers.
-
#payment_arrangements ⇒ Object
readonly
Returns the value of attribute payment_arrangements.
-
#payment_methods ⇒ Object
readonly
Returns the value of attribute payment_methods.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#prices ⇒ Object
readonly
Returns the value of attribute prices.
Class Method Summary collapse
- .by_address(lat: nil, lng: nil, fuel_type: 'DIE', closed: 'true') ⇒ Object
- .by_region(code: nil, region_type: nil, fuel_type: 'DIE', closed: 'true') ⇒ Object
- .conn ⇒ Object
Instance Method Summary collapse
-
#initialize(station) ⇒ Station
constructor
A new instance of Station.
Constructor Details
#initialize(station) ⇒ Station
Returns a new instance of Station.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/spritpreisrechner/station.rb', line 9 def initialize(station) @id = station[:id] @name = station[:name] @location = Location.new(station[:location]) @contact = Contact.new(station[:contact]) @opening_hours = [] @offer_information = OfferInformation.new(station[:offerInformation]) @payment_methods = PaymentMethod.new(station[:paymentMethods]) @payment_arrangements = PaymentArrengement.new(station[:paymentArrangements]) @other_service_offers = station[:otherServiceOffers]&.split(', ') @position = station[:position].to_i @open = station[:open] @distance = station[:distance].to_f @prices = [] station[:openingHours].each do |opening_hour| @opening_hours << OpeningHour.new(opening_hour) end station[:prices].each do |price| @prices << Price.new(price) end end |
Instance Attribute Details
#contact ⇒ Object (readonly)
Returns the value of attribute contact.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def contact @contact end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
3 4 5 |
# File 'lib/spritpreisrechner/station.rb', line 3 def distance @distance end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/spritpreisrechner/station.rb', line 3 def id @id end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/spritpreisrechner/station.rb', line 3 def name @name end |
#offer_information ⇒ Object (readonly)
Returns the value of attribute offer_information.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def offer_information @offer_information end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
3 4 5 |
# File 'lib/spritpreisrechner/station.rb', line 3 def open @open end |
#opening_hours ⇒ Object (readonly)
Returns the value of attribute opening_hours.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def opening_hours @opening_hours end |
#other_service_offers ⇒ Object (readonly)
Returns the value of attribute other_service_offers.
3 4 5 |
# File 'lib/spritpreisrechner/station.rb', line 3 def other_service_offers @other_service_offers end |
#payment_arrangements ⇒ Object (readonly)
Returns the value of attribute payment_arrangements.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def payment_arrangements @payment_arrangements end |
#payment_methods ⇒ Object (readonly)
Returns the value of attribute payment_methods.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def payment_methods @payment_methods end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
3 4 5 |
# File 'lib/spritpreisrechner/station.rb', line 3 def position @position end |
#prices ⇒ Object (readonly)
Returns the value of attribute prices.
4 5 6 |
# File 'lib/spritpreisrechner/station.rb', line 4 def prices @prices end |
Class Method Details
.by_address(lat: nil, lng: nil, fuel_type: 'DIE', closed: 'true') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spritpreisrechner/station.rb', line 34 def self.by_address(lat: nil, lng: nil, fuel_type: 'DIE', closed: 'true') errors = [] errors << 'you need to submit a valid latitude coordinate' if lat.nil? errors << 'you need to submit a valid longitude coordinate' if lng.nil? errors << "you need to submit a valid Fuel Type. The options are #{FUEL_TYPES}" if fuel_type.nil? || !FUEL_TYPES.include?(fuel_type) return Response.new(errors: errors) if errors.any? response = conn.get('search/gas-stations/by-address', latitude: lat, longitude: lng, fuelType: fuel_type, includeClosed: closed) attributes = JSON.parse(response.body, symbolize_names: true) response = Response.new(attributes) response.stations = [] if response.success? attributes.each do |station| response.stations << Station.new(station) end end response end |
.by_region(code: nil, region_type: nil, fuel_type: 'DIE', closed: 'true') ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/spritpreisrechner/station.rb', line 55 def self.by_region(code: nil, region_type: nil, fuel_type: 'DIE', closed: 'true') errors = [] errors << 'you need to submit a valid region code' if code.nil? errors << "you need to submit a valid region type. The options are #{REGION_TYPES}" if region_type.nil? || !REGION_TYPES.include?(region_type) errors << "you need to submit a valid Fuel Type. The options are #{FUEL_TYPES}" if fuel_type.nil? || !FUEL_TYPES.include?(fuel_type) return Response.new(errors: errors) if errors.any? response = conn.get('search/gas-stations/by-region', code: code, type: region_type, fuelType: fuel_type, includeClosed: closed) attributes = JSON.parse(response.body, symbolize_names: true) response = Response.new(attributes) response.stations = [] if response.success? attributes.each do |station| response.stations << Station.new(station) end end response end |
.conn ⇒ Object
76 77 78 |
# File 'lib/spritpreisrechner/station.rb', line 76 def self.conn Spritpreisrechner.conn end |