aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sale.rb
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2014-11-13 17:54:55 +0100
committerHarald Eilertsen <haraldei@anduin.net>2014-11-13 17:54:55 +0100
commit33b2c7b846962bc92b7ea32049ab2e0502cd4d80 (patch)
tree6d7764253fc499cb1db63393bd6cb2395ae0f06b /lib/sale.rb
parent91387893047f9b02cb0e9741f4843161e2e78179 (diff)
downloadimusician-reports-33b2c7b846962bc92b7ea32049ab2e0502cd4d80.tar.gz
imusician-reports-33b2c7b846962bc92b7ea32049ab2e0502cd4d80.tar.bz2
imusician-reports-33b2c7b846962bc92b7ea32049ab2e0502cd4d80.zip
Make Sale class.
Diffstat (limited to 'lib/sale.rb')
-rw-r--r--lib/sale.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/sale.rb b/lib/sale.rb
new file mode 100644
index 0000000..f02a471
--- /dev/null
+++ b/lib/sale.rb
@@ -0,0 +1,25 @@
+module SalesReporter
+ class Sale
+ attr_reader :date, :amount, :quantity
+
+ def initialize(date_, amount, quantity)
+ @date = sanitize_date(date_)
+ raise TypeError('sanitize failed') unless @date.is_a? Date
+ @amount = amount
+ @quantity = quantity
+ end
+
+ private
+
+ def sanitize_date(d)
+ case d.class.to_s
+ when "String"
+ return Date.parse(d)
+ when "Date"
+ return d
+ else
+ raise TypeError.new('Expected date argument to be of type Date or String')
+ end
+ end
+ end
+end