Created
November 12, 2012 23:54
-
-
Save michaelfeathers/4062900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ostruct' | |
require 'date' | |
class OrdersReport < Struct.new(:orders,:date_range) | |
def total_sales_within_date_range | |
orders.select {|order| date_range.include?(order.placed_at) } | |
.map(&:amount) | |
.reduce(0.0,:+) | |
end | |
end | |
class DateRange < Struct.new(:start_date, :end_date) | |
def include?(date) | |
(start_date..end_date).cover? date | |
end | |
end | |
class Order < Struct.new(:amount, :placed_at) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment