class TeaShopper::Tea
Attributes
date[RW]
description[RW]
flavors[RW]
name[RW]
price[RW]
price_per_oz[RW]
region[RW]
shop_name[RW]
size[RW]
stock[RW]
type[RW]
url[RW]
Public Class Methods
all()
click to toggle source
@@all Teas reader
# File lib/tea.rb, line 34 def self.all return @@all end
create_from_collection(tea_array)
click to toggle source
Create tea instances from hashes inside tea_array
# File lib/tea.rb, line 14 def self.create_from_collection(tea_array) tea_array.each do |tea| tea = TeaShopper::Tea.new({ :name => tea[:name], :type => tea[:type], :shop_name => tea[:shop_name], :url => tea[:url], :stock => tea[:stock] }) # Future: reinstate :region => tea[:region], end end
find_by_name(name, array)
click to toggle source
Find tea object by name
# File lib/tea.rb, line 44 def self.find_by_name(name, array) array.find{|obj| obj.name.downcase == name.downcase} end
new(attributes)
click to toggle source
Initialize multiple attributes with send
# File lib/tea.rb, line 8 def initialize(attributes) attributes.each {|key, value| self.send(("#{key}="), value)} @@all << self end
no_description?(type)
click to toggle source
Return true if sample description doesn't exist for tea in input type
# File lib/tea.rb, line 49 def self.no_description?(type) self.teas_by_type(type).select{|obj| obj.description}.sample.nil? end
reset_all()
click to toggle source
Reset the @@all array
# File lib/tea.rb, line 39 def self.reset_all self.all.clear end
teas_by_type(type)
click to toggle source
Return array of teas for type
# File lib/tea.rb, line 59 def self.teas_by_type(type) teas = self.all.collect { |obj| obj if obj.type == type }.compact # teas.sort_by { |tea| tea.price_per_oz} # for sorting by price, rather than alphabetical teas.sort_by { |tea| tea.name} end
types()
click to toggle source
Return array of tea types
# File lib/tea.rb, line 54 def self.types self.all.collect { |tea| tea.type }.uniq.sort end
Public Instance Methods
add_tea_attributes(attributes_hash)
click to toggle source
Add profile page hash attributes to Tea
objects
# File lib/tea.rb, line 28 def add_tea_attributes(attributes_hash) attributes_hash.each {|key, value| self.send(("#{key}="), value)} return self end