Class: Flicks::Movie
Direct Known Subclasses
Instance Attribute Summary collapse
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#snack_carbs ⇒ Object
readonly
Returns the value of attribute snack_carbs.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #ate_snack(snack) ⇒ Object
- #carbs_consumed ⇒ Object
- #expose_hash ⇒ Object
-
#initialize(title, rank = 0) ⇒ Movie
constructor
A new instance of Movie.
- #to_s ⇒ Object
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
#rank ⇒ Object
Returns the value of attribute rank.
8 9 10 |
# File 'lib/movie.rb', line 8 def rank @rank end |
#snack_carbs ⇒ Object (readonly)
Returns the value of attribute snack_carbs.
7 8 9 |
# File 'lib/movie.rb', line 7 def snack_carbs @snack_carbs end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/movie.rb', line 7 def title @title end |
Class Method Details
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_consumed ⇒ Object
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_hash ⇒ Object
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_s ⇒ Object
43 44 45 |
# File 'lib/movie.rb', line 43 def to_s "#{@title} with a rank of #{@rank} (#{status})" end |