Skip to content

Instantly share code, notes, and snippets.

@iande
Created May 24, 2011 23:09
Show Gist options
  • Select an option

  • Save iande/989971 to your computer and use it in GitHub Desktop.

Select an option

Save iande/989971 to your computer and use it in GitHub Desktop.
Blah blah STI
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