Class: Ratis::Plantrip
- Inherits:
-
Object
- Object
- Ratis::Plantrip
- Defined in:
- lib/ratis/plantrip.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#itineraries ⇒ Object
Returns the value of attribute itineraries.
-
#success ⇒ Object
Returns the value of attribute success.
-
#tid ⇒ Object
Returns the value of attribute tid.
-
#walkable ⇒ Object
Returns the value of attribute walkable.
-
#walkadjust ⇒ Object
Returns the value of attribute walkadjust.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ Plantrip
constructor
A new instance of Plantrip.
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Plantrip
Returns a new instance of Plantrip.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ratis/plantrip.rb', line 7 def initialize(response) @success = response.success? @walkable = response.body[:walkable] @walkadjust = response.body[:walkadjust] @input = response.body[:plantrip_response][:input] @itineraries = response.to_array(:plantrip_response, :itin).map do |itinerary| Itinerary.new(itinerary) end @tid = response.body[:plantrip_response][:tid] end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
5 6 7 |
# File 'lib/ratis/plantrip.rb', line 5 def input @input end |
#itineraries ⇒ Object
Returns the value of attribute itineraries.
5 6 7 |
# File 'lib/ratis/plantrip.rb', line 5 def itineraries @itineraries end |
#success ⇒ Object
Returns the value of attribute success.
5 6 7 |
# File 'lib/ratis/plantrip.rb', line 5 def success @success end |
#tid ⇒ Object
Returns the value of attribute tid.
5 6 7 |
# File 'lib/ratis/plantrip.rb', line 5 def tid @tid end |
#walkable ⇒ Object
Returns the value of attribute walkable.
5 6 7 |
# File 'lib/ratis/plantrip.rb', line 5 def walkable @walkable end |
#walkadjust ⇒ Object
Returns the value of attribute walkadjust.
5 6 7 |
# File 'lib/ratis/plantrip.rb', line 5 def walkadjust @walkadjust end |
Class Method Details
.where(conditions) ⇒ Object
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ratis/plantrip.rb', line 21 def self.where(conditions) minimize = conditions.delete(:minimize).try(:upcase) || 'T' arrdep = conditions.delete(:arrdep).try(:upcase) || "D" maxanswers = conditions.delete(:maxanswers) || '3' xmode = conditions.delete(:xmode) || 'BCFKLRSTX' walkdist = conditions.delete(:walkdist) || "0.50" origin_lat = conditions.delete(:origin_lat).to_f origin_long = conditions.delete(:origin_long).to_f origin_text = conditions.delete(:origin_text) origin_landmark_id = conditions.delete(:origin_landmark_id) destination_lat = conditions.delete(:destination_lat).to_f destination_long = conditions.delete(:destination_long).to_f destination_text = conditions.delete(:destination_text) destination_landmark_id = conditions.delete(:destination_landmark_id) tid = conditions.delete(:tid) if datetime = conditions.delete(:datetime) raise ArgumentError.new('If datetime supplied it should be a Time or DateTime instance, otherwise it defaults to Time.now') unless datetime.is_a?(DateTime) || datetime.is_a?(Time) else datetime = Time.now end 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 params = {'Date' => datetime.strftime("%m/%d/%Y"), 'Time' => datetime.strftime("%H%M"), 'Minimize' => minimize, 'Arrdep' => arrdep, 'Maxanswers' => maxanswers, 'Walkdist' => walkdist, 'Xmode' => xmode, 'Originlat' => origin_lat, 'Originlong' => origin_long, 'Origintext' => origin_text, 'Originlandmarkid' => origin_landmark_id, 'Destinationlat' => destination_lat, 'Destinationlong' => destination_long, 'Destinationtext' => destination_text, 'Destinationlandmarkid' => destination_landmark_id} params['Tid'] = tid unless tid.nil? response = Request.get 'Plantrip', params Plantrip.new(response) end |
Instance Method Details
#success? ⇒ Boolean
76 77 78 |
# File 'lib/ratis/plantrip.rb', line 76 def success? @success end |