Created
May 24, 2011 23:09
-
-
Save iande/989971 to your computer and use it in GitHub Desktop.
Blah blah STI
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
| class Result | |
| # Possible attributes: | |
| # seller_name: String, nil | |
| # title : String, nil | |
| # description: String | |
| # price : Decimal | |
| def human_readable_on_base | |
| str = if self.title | |
| "#{self.title} " | |
| else | |
| '' | |
| end | |
| str += if self.seller_name | |
| if str.length > 0 | |
| " by #{self.seller_name}: " | |
| else | |
| "#{self.seller_name}: " | |
| end | |
| else | |
| ": " | |
| end | |
| str + price.to_s | |
| end | |
| end | |
| class Site1Result < Result | |
| # From Site1, we get all fields | |
| def human_readable | |
| "#{self.title} by #{self.seller_name}: #{self.price.to_s}" | |
| end | |
| end | |
| class Site2Result < Result | |
| # Site2 does not provide a seller_name | |
| def human_readable | |
| "#{self.title}: #{self.price.to_s}" | |
| end | |
| end | |
| class Site3Result < Result | |
| # Site3 does not provide a title. | |
| def human_readable | |
| "#{self.seller_name}: #{self.price.to_s}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment