Class: Ratis::Itinerary
- Inherits:
-
Object
- Object
- Ratis::Itinerary
- Defined in:
- lib/ratis/itinerary.rb
Instance Attribute Summary collapse
-
#co2_auto ⇒ Object
Returns the value of attribute co2_auto.
-
#co2_transit ⇒ Object
Returns the value of attribute co2_transit.
-
#final_walk_dir ⇒ Object
Returns the value of attribute final_walk_dir.
-
#legs ⇒ Object
Returns the value of attribute legs.
-
#reduced_fare ⇒ Object
Returns the value of attribute reduced_fare.
-
#regular_fare ⇒ Object
Returns the value of attribute regular_fare.
-
#transit_time ⇒ Object
Returns the value of attribute transit_time.
Class Method Summary collapse
Instance Attribute Details
#co2_auto ⇒ Object
Returns the value of attribute co2_auto.
5 6 7 |
# File 'lib/ratis/itinerary.rb', line 5 def co2_auto @co2_auto end |
#co2_transit ⇒ Object
Returns the value of attribute co2_transit.
5 6 7 |
# File 'lib/ratis/itinerary.rb', line 5 def co2_transit @co2_transit end |
#final_walk_dir ⇒ Object
Returns the value of attribute final_walk_dir.
6 7 8 |
# File 'lib/ratis/itinerary.rb', line 6 def final_walk_dir @final_walk_dir end |
#legs ⇒ Object
Returns the value of attribute legs.
6 7 8 |
# File 'lib/ratis/itinerary.rb', line 6 def legs @legs end |
#reduced_fare ⇒ Object
Returns the value of attribute reduced_fare.
7 8 9 |
# File 'lib/ratis/itinerary.rb', line 7 def reduced_fare @reduced_fare end |
#regular_fare ⇒ Object
Returns the value of attribute regular_fare.
7 8 9 |
# File 'lib/ratis/itinerary.rb', line 7 def regular_fare @regular_fare end |
#transit_time ⇒ Object
Returns the value of attribute transit_time.
8 9 10 |
# File 'lib/ratis/itinerary.rb', line 8 def transit_time @transit_time end |
Class Method Details
.where(conditions) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ratis/itinerary.rb', line 10 def self.where(conditions) date = conditions.delete :date time = conditions.delete :time minimize = conditions.delete(:minimize).to_s.upcase origin_lat = conditions.delete(:origin_lat).to_f origin_long = conditions.delete(:origin_long).to_f destination_lat = conditions.delete(:destination_lat).to_f destination_long = conditions.delete(:destination_long).to_f raise ArgumentError.new('You must provide a date DD/MM/YYYY') unless DateTime.strptime(date, '%d/%m/%Y') rescue false raise ArgumentError.new('You must provide a time as 24-hour HHMM') unless DateTime.strptime(time, '%H%M') rescue false raise ArgumentError.new('You must provide a conditions of T|X|W to minimize') unless ['T', 'X', 'W'].include? minimize raise ArgumentError.new('You must provide an origin latitude') unless Ratis.valid_latitude? origin_lat raise ArgumentError.new('You must provide an origin longitude') unless Ratis.valid_longitude? origin_long raise ArgumentError.new('You must provide an destination latitude') unless Ratis.valid_latitude? destination_lat raise ArgumentError.new('You must provide an destination longitude') unless Ratis.valid_longitude? destination_long Ratis.all_conditions_used? conditions response = Request.get 'Plantrip', 'Date' => date, 'Time' => time, 'Minimize' => minimize, 'Originlat' => origin_lat, 'Originlong' => origin_long, 'Destinationlat' => destination_lat, 'Destinationlong' => destination_long return [] unless response.success? response.to_array(:plantrip_response, :itin).map do |itinerary| atis_itinerary = Itinerary.new atis_itinerary.co2_auto = itinerary[:co2auto].to_f atis_itinerary.co2_transit = itinerary[:co2transit].to_f atis_itinerary.final_walk_dir = itinerary[:finalwalkdir] atis_itinerary.reduced_fare = itinerary[:reducedfare].to_f atis_itinerary.regular_fare = itinerary[:regularfare].to_f atis_itinerary.transit_time = itinerary[:transittime].to_i atis_itinerary.legs = itinerary.to_array :legs, :leg atis_itinerary end end |