Class: KondutoTravel
- Inherits:
-
Object
- Object
- KondutoTravel
- Defined in:
- lib/konduto-ruby/konduto_travel.rb
Constant Summary collapse
- TYPE_TRAVEL =
[:flight, :bus]
Instance Attribute Summary collapse
-
#departure ⇒ Object
Returns the value of attribute departure.
-
#passengers ⇒ Object
Returns the value of attribute passengers.
-
#return ⇒ Object
Returns the value of attribute return.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_passenger(passenger) ⇒ Object
-
#initialize(*args) ⇒ KondutoTravel
constructor
A new instance of KondutoTravel.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(*args) ⇒ KondutoTravel
Returns a new instance of KondutoTravel.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 8 def initialize(*args) self.passengers = [] if args[0].nil? self.departure = KondutoTravelInfo.new self.return = KondutoTravelInfo.new else if args[0][:departure].nil? self.departure = KondutoTravelInfo.new else self.departure = KondutoTravelInfo.new args[0][:departure] args[0].delete :departure end if args[0][:return].nil? self.return = KondutoTravelInfo.new else self.return = KondutoTravelInfo.new args[0][:return] args[0].delete :return end args[0].each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end end |
Instance Attribute Details
#departure ⇒ Object
Returns the value of attribute departure.
5 6 7 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 5 def departure @departure end |
#passengers ⇒ Object
Returns the value of attribute passengers.
5 6 7 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 5 def passengers @passengers end |
#return ⇒ Object
Returns the value of attribute return.
5 6 7 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 5 def return @return end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 5 def type @type end |
Instance Method Details
#add_passenger(passenger) ⇒ Object
34 35 36 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 34 def add_passenger (passenger) self.passengers << passenger end |
#to_hash ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 38 def to_hash hash = { type: self.type, departure: self.departure.to_hash, return: self.return.to_hash, passengers: KondutoUtils.array_to_hash(self.passengers) } KondutoUtils.remove_nil_keys_from_hash(hash) end |
#to_json ⇒ Object
48 49 50 |
# File 'lib/konduto-ruby/konduto_travel.rb', line 48 def to_json self.to_hash.to_json end |