Created
July 7, 2014 14:11
-
-
Save chaadow/1a25ecfef76c27c1f0c7 to your computer and use it in GitHub Desktop.
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
class ItemDecorator | |
def self.build_collection(items) | |
items.map { |item| new(item) } | |
end | |
def initialize(item) | |
@item = item | |
end | |
def is_featured? | |
@item.ratings > 5 | |
end | |
def status | |
if @item.sold? | |
"Sold on #{@item.sold_on.strftime('%A, %B %e')}" | |
else | |
"Available" | |
end | |
end | |
def method_missing(method_name, *args, &block) | |
@item.send(method_name, *args, &block) | |
end | |
def respond_to_missing?(method_name, include_private = false) | |
@item.respond_to?(method_name, include_private) || super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment