Permalink
Browse files

Small fixes. Add (stolen) readme.

  • Loading branch information...
marcheiligers committed Jun 11, 2012
1 parent fff24cb commit 56f31b1f2ef55c7d2e34d01c418289daf6891a74
Showing with 44 additions and 7 deletions.
  1. +40 −0 ruby/marcheiligers/README.md
  2. +4 −7 ruby/marcheiligers/prices.rb
@@ -0,0 +1,40 @@
+This README stolen from apauly's version and tweaked.
+
+How to run this Ruby version
+============================
+
+* Change to this directory in a terminal
+
+* Run prices.rb
+
+ > $ ruby prices.rb
+
+* Look at the contents of pricefile.txt
+
+
+About the Code
+==============
+
+The example lends itself to a simple Product/Fruit object hierarchy,
+which is totally not what I've used here. Unlike _apauly_, instead I've
+decided that products are products, but there are Rules which change
+how a Product's markup and shelf life is calculated.
+
+The extra supplier logic is something which does not fit in with the
+_apualy_'s hierarchy, doesn't exist in this example. Instead all Products
+are tested against all Rules and those rules that match a product are
+applied. There are the basic fruit rules which set markup % and shelf
+life in days, and then the special Supplier rules which actually
+override the way the calculations are done. All the rules use some mild
+meta-programming, which I like.
+
+Some interesting features:
+* Rules are never actually instantiated.
+* It's really easy to add additional Rules, both for new types of Fruit
+and for new Supplier "issues". But, there's no support for Supplier rules
+that apply to the same product. I haven't thought about how one might
+implement that using this solution.
+* The actual LabelPrinter class just pulls functionality from the 3
+Modules. It's really easy to split the responsibilities, add rules, even
+have multiple different label printers, perhaps for different shops.
+* In a very non-Rubyist approach, I've done no testing what-so-ever :(
@@ -19,9 +19,6 @@ def initialize(supplier_id, product_code, description, delivery_date, cost_price
@delivery_date = Date.parse delivery_date
@cost_price = cost_price.to_i
@unit_count = unit_count.to_i
-
- @markup = 0.5
- @shelf_life = 7
end
def selling_price
@@ -104,9 +101,9 @@ def apply!(product)
end
class FruitRule < Rule
- product_codes 1100, 1199
- markup 0.4
- shelf_life 14
+ product_codes 1000, 1999
+ markup 0.5
+ shelf_life 7
end
class AppleRule < Rule
@@ -126,7 +123,7 @@ class BerryRule < Rule
markup 0.55
end
-class SupplierRule
+class SupplierRule < Rule
def self.for_suppliers(*ids)
suppliers.concat ids
self

0 comments on commit 56f31b1

Please sign in to comment.