Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Item
- attr_accessor :name, :terms, :description
- def initialize name
- @name = name
- end
- def self.list items
- items.collect { |item| item.terms.first }.join("\n")
- end
- def self.describe items
- items.collect { |item| item.description }.join("\n")
- end
- def self.find items, term
- return if term.empty? || items.empty?
- items.collect do |name,item|
- name unless item.terms.grep(/#{term}/i).empty?
- end.compact.first
- end
- def setup attribute, *args
- case attribute
- when :description
- @description = args.compact.join(" ")
- when :terms
- @terms = args.first.split(', ')
- end
- end
- end
Add Comment
Please, Sign In to add comment