class Trip

Constants

WHITELISTED_ATTRS

Public Class Methods

new(hash) click to toggle source
# File lib/blabla_client/trip.rb, line 12
def initialize(hash)
  self.attributes = hash.keep_if {|k,v| WHITELISTED_ATTRS.include?(k)}
end
parse_response(json_response) click to toggle source
# File lib/blabla_client/trip.rb, line 16
def self.parse_response(json_response)
  response = {}
  response_hash = JSON.parse json_response, :symbolize_names => true
  unless response_hash[:trips].nil?
    response[:trips] = response_hash[:trips].collect {|t| Trip.new(t)}
  end
  unless response_hash[:pager].nil?
    response[:page] = response_hash[:pager][:page]
    response[:pages] = response_hash[:pager][:pages]
    response[:count] = response_hash[:pager][:total]
  end
  response
end

Public Instance Methods

get_arrival_place() click to toggle source
# File lib/blabla_client/trip.rb, line 51
def get_arrival_place
  full_address = arrival_place[:address]
  full_address += ", #{arrival_place[:city_name]}" unless arrival_place[:address].include?(arrival_place[:city_name])
  full_address
end
get_car() click to toggle source
# File lib/blabla_client/trip.rb, line 72
def get_car
  car_hash = {}
  unless car.nil? || car.empty?
    car_hash[:model] = car[:make]
    car_hash[:model] += " #{car[:model]}" unless car[:model].nil?
    car_hash[:comfort] = car[:comfort_nb_star]
  end
  car_hash
end
get_departure_date() click to toggle source
# File lib/blabla_client/trip.rb, line 38
def get_departure_date
  departure_fields = departure_date.split(' ')
  date_fields = departure_fields[0].split('/')
  time_fields = departure_fields[1].split(':')
  Time.new(date_fields[2].to_i, date_fields[1].to_i, date_fields[0].to_i, time_fields[0].to_i, time_fields[1].to_i, time_fields[2].to_i)
end
get_departure_place() click to toggle source
# File lib/blabla_client/trip.rb, line 45
def get_departure_place
  full_address = departure_place[:address]
  full_address += ", #{departure_place[:city_name]}" unless departure_place[:address].include?(departure_place[:city_name])
  full_address
end
get_distance() click to toggle source
# File lib/blabla_client/trip.rb, line 68
def get_distance
  distance[:value] unless distance.nil?
end
get_duration() click to toggle source
# File lib/blabla_client/trip.rb, line 57
def get_duration
  duration_hash = {}
  unless duration.nil? || duration.empty?
    if duration[:unity] == 's'
      duration_hash[:hours] = (duration[:value].to_f/3600).floor
      duration_hash[:minutes] = ((duration[:value] - duration_hash[:hours]*3600).to_f/60).floor
    end
  end
  duration_hash
end
get_price() click to toggle source
# File lib/blabla_client/trip.rb, line 34
def get_price
  {:value => price[:value], :currency => price[:symbol], :color => price[:price_color].downcase}
end
get_url() click to toggle source
# File lib/blabla_client/trip.rb, line 30
def get_url
  links[:_front]
end