Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fff24cb
commit 56f31b1
Showing
2 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 :( |
This file contains 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