Class: Flicks::Movie

Inherits:
Object
  • Object
show all
Includes:
Rankable
Defined in:
lib/movie.rb

Direct Known Subclasses

Movie3D

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rankable

#<=>, #hit?, #normalized_rank, #status, #thumbs_down, #thumbs_up

Constructor Details

#initialize(title, rank = 0) ⇒ Movie

Returns a new instance of Movie.



10
11
12
13
14
# File 'lib/movie.rb', line 10

def initialize(title, rank=0)
	@title = title.capitalize
	@rank = rank
	@snack_carbs = Hash.new(0)
end

Instance Attribute Details

#rankObject

Returns the value of attribute rank.



8
9
10
# File 'lib/movie.rb', line 8

def rank
  @rank
end

#snack_carbsObject (readonly)

Returns the value of attribute snack_carbs.



7
8
9
# File 'lib/movie.rb', line 7

def snack_carbs
  @snack_carbs
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/movie.rb', line 7

def title
  @title
end

Class Method Details

.convert(line) ⇒ Object



16
17
18
19
# File 'lib/movie.rb', line 16

def self.convert(line)
	title,rank = line.split(',')
	Movie.new(title,Integer(rank))
end

Instance Method Details

#ate_snack(snack) ⇒ Object



33
34
35
36
37
# File 'lib/movie.rb', line 33

def ate_snack(snack)
	@snack_carbs[snack.name] += snack.carbs
	puts "Sold ~> #{snack.name.capitalize} - #{snack.carbs} carbs" 
	puts @snack_carbs
end

#carbs_consumedObject



28
29
30
31
# File 'lib/movie.rb', line 28

def carbs_consumed
	@snack_carbs.values.reduce(0) {|sum,snack| sum + snack }
	# @snacks_carbs.values.reduce(0,:+)
end

#expose_hashObject



21
22
23
24
25
26
# File 'lib/movie.rb', line 21

def expose_hash           
	@snack_carbs.each do |key,value|
		snack = Snack.new(key,value.to_i)
		yield(snack)
	end
end

#to_sObject



43
44
45
# File 'lib/movie.rb', line 43

def to_s
	"#{@title} with a rank of #{@rank} (#{status})"
end