Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class Item
  2. attr_accessor :name, :terms, :description
  3.  
  4. def initialize name
  5. @name = name
  6. end
  7.  
  8. def self.list items
  9. items.collect { |item| item.terms.first }.join("\n")
  10. end
  11.  
  12. def self.describe items
  13. items.collect { |item| item.description }.join("\n")
  14. end
  15.  
  16. def self.find items, term
  17. return if term.empty? || items.empty?
  18. items.collect do |name,item|
  19. name unless item.terms.grep(/#{term}/i).empty?
  20. end.compact.first
  21. end
  22.  
  23. def setup attribute, *args
  24. case attribute
  25. when :description
  26. @description = args.compact.join(" ")
  27. when :terms
  28. @terms = args.first.split(', ')
  29. end
  30. end
  31. end
Add Comment
Please, Sign In to add comment