Class: QuickTravel::PassengerType

Inherits:
Adapter
  • Object
show all
Defined in:
lib/quick_travel/mock.rb,
lib/quick_travel/passenger_type.rb

Class Method Summary collapse

Methods inherited from Adapter

belongs_to, create, find, has_many, #to_s, update

Methods included from InitFromHash

#define_readers, #initialize, #to_hash

Class Method Details

.allObject



20
21
22
23
24
25
# File 'lib/quick_travel/mock.rb', line 20

def self.all
  [
    PassengerType.new(id: 1, name: 'Adult'),
    PassengerType.new(id: 2, name: 'Child')
  ]
end

.passenger_counts(count_hash) ⇒ Object



8
9
10
11
12
13
# File 'lib/quick_travel/passenger_type.rb', line 8

def self.passenger_counts(count_hash)
  applicable_types = count_hash.reject { |_t, c| c.zero? }
  applicable_types.map do |type, count|
    pluralize(count, find(type).try(:name))
  end
end

.pluralize(count, singular, plural = nil) ⇒ Object



15
16
17
# File 'lib/quick_travel/passenger_type.rb', line 15

def self.pluralize(count, singular, plural = nil)
  "#{count || 0} " + ((count == 1) ? singular : (plural || singular.pluralize))
end