Skip to content

Instantly share code, notes, and snippets.

@brentonannan
Last active October 11, 2016 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentonannan/eb548290b389425e75a32de509072658 to your computer and use it in GitHub Desktop.
Save brentonannan/eb548290b389425e75a32de509072658 to your computer and use it in GitHub Desktop.
class Policy
def price
@price = Settings.policy.base_rate + Settings.policy.extra_traveller_discount * (@travellers.length - 1)
@travellers.each do |traveller|
@price += @destination.day_rate(traveller.age) * (@end_date - @start_date).to_i
end
end
end
class Destination
def day_rate(age)
@day_rate * Statistics.function(Setting.policy.optimal_age, age)
end
end
class Policy
def price
@price = base_rate + Settings.policy.multi_traveller_discount * (@travellers.length - 1)
@travellers.each do |traveller|
@price += trip_price(traveller)
end
end
private
def base_rate
Settings.policy.base_rate
end
def multi_traveller_discount
Settings.policy.multi_traveller_discount
end
def trip_price(traveller)
@destination.day_rate(traveller.age) * trip_length
end
def trip_length
(@end_date - @start_date).to_i
end
end
class Policy
def price
Policy::Pricing.base_price(Settings.policy.base_rate, Settings.policy.multi_traveller_discount, @travellers.length) +
@travellers.reduce(:+) { |traveller| Policy::Pricing.traveller_trip_price(Setting.policy.optimal_age, traveller.age, @destination.day_rate, trip_length) }
end
end
class Destination
attr_reader :day_rate
end
module Policy::Pricing
def base_price(base_rate, multi_traveller_discount, number_of_travellers)
base_rate + (1 - multi_traveller_discount) * (number_of_travellers - 1)
end
module_function :base_price
def traveller_trip_price(optimal_age, traveller_age, day_rate, trip_length)
day_rate * Statistics.function(optimal_age, traveller_age) * trip_length
end
module_function :traveller_trip_price
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment