Sha256: 690756531d5f422be6f0f6c416040f039bb1494ec1f67dacb501b34b7c445ace

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

# This class ...
class BestWhiskey::Whiskey

	attr_accessor :name,
								:award,
								:abv,
								:category,
								:style,
								:country,
								:producer,
								:description,
								:age,
								:winning_year,
								:vintage

	@@all = []

	def initialize(attribute_hash)
		attribute_hash.each do | k, v |
			self.send( "#{k}=", v )
		end
		@@all << self
	end

	def self.create_whiskey_from_scrp(attribute_hash)
		self.new(attribute_hash).tap do |whiskey|
			whiskey.associate_year(whiskey.winning_year)
			whiskey.winning_year.each { |w| w.add_whiskey(whiskey) }
		end
	end

	def associate_year(year)
		y = year.map { |year| BestWhiskey::ContestYear.find_or_create_by_year(year) }
		self.winning_year = y
	end

	def self.all
		@@all
	end

	def self.attributes
		[ :name,
			:award,
		  :abv,
			:category,
			:style,
			:country,
			:producer,
			:description,
			:age,
			:vintage
		]
	end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
best_whiskey-0.1.1 lib/best_whiskey/whiskey.rb