Skip to content

Instantly share code, notes, and snippets.

@regedarek
Created August 18, 2012 20:04
Show Gist options
  • Save regedarek/4f9a62860e5a91d0de57 to your computer and use it in GitHub Desktop.
Save regedarek/4f9a62860e5a91d0de57 to your computer and use it in GitHub Desktop.
# Code below works for me
cars_types = [
{"car_type"=>"11", "car_features"=>"21"}, # car one
{"car_type"=>"12", "car_features"=>"22"} # car two
]
# cars_results = [
# {"car_badge"=>"typical", "car_doors"=>"5"}, # car one
# {"car_badge"=>"typical", "car_doors"=>"3"} # car two
# ]
...
class CarRental
attr_accessor :car_type, :car_features, :car_badge, :car_doors
def initialize(data)
@one = data["car_type"]
@two = data["car_features"]
# @three = data["car_badge"]
# @four = data["car_doors"]
end
class << self
def find(info)
array_1.map do |data|
CarRental.new(data)
end
end
...
@regedarek
Copy link
Author

Now I would like to add next array to this:

cars_results = [
  {"car_badge"=>"typical", "car_doors"=>"5"}, # car one
  {"car_badge"=>"typical", "car_doors"=>"3"}  # car two
]

@regedarek
Copy link
Author

This should be something like:

        [array_1, array_2].map do |data|
          CarRental.new(data)
        end

@regedarek
Copy link
Author

https://github.com/thoughtfusion/suitcase/blob/master/lib/suitcase/car_rental.rb

Link to gem. And documentation => http://developer.hotwire.com/docs/read/Rental_Car_Shopping_API

Basicaly I would like to extend


    def initialize(data)
      @seating = data["CarTypeSeating"]
      @type_name = data["CarTypeName"]
      @type_code = data["CarTypeCode"]
      @possible_features = data["PossibleFeatures"].split(", ")
      @possible_models = data["PossibleModels"].split(", ")
    end

by new params from parsed["Result"] array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment