Class: Flicks::Movie
Direct Known Subclasses
Instance Attribute Summary collapse
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#snacks_eaten ⇒ Object
readonly
Returns the value of attribute snacks_eaten.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #add_snack(name, price) ⇒ Object
-
#initialize(title, rank = 5) ⇒ Movie
constructor
A new instance of Movie.
- #to_csv ⇒ Object
- #to_s ⇒ Object
- #total_snack_price ⇒ Object
Methods included from Rankable
Constructor Details
#initialize(title, rank = 5) ⇒ Movie
Returns a new instance of Movie.
10 11 12 13 14 |
# File 'lib/flicks/movie.rb', line 10 def initialize(title, rank = 5) @title = title.capitalize @rank = rank @snacks_eaten = Hash.new(0) end |
Instance Attribute Details
#rank ⇒ Object
Returns the value of attribute rank.
8 9 10 |
# File 'lib/flicks/movie.rb', line 8 def rank @rank end |
#snacks_eaten ⇒ Object (readonly)
Returns the value of attribute snacks_eaten.
7 8 9 |
# File 'lib/flicks/movie.rb', line 7 def snacks_eaten @snacks_eaten end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/flicks/movie.rb', line 8 def title @title end |
Class Method Details
Instance Method Details
#add_snack(name, price) ⇒ Object
16 17 18 |
# File 'lib/flicks/movie.rb', line 16 def add_snack(name, price) @snacks_eaten[name] += price end |
#to_csv ⇒ Object
32 33 34 |
# File 'lib/flicks/movie.rb', line 32 def to_csv "#{@title},#{@rank}" end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/flicks/movie.rb', line 36 def to_s "#{@title} has a rank of #{@rank}" end |
#total_snack_price ⇒ Object
20 21 22 |
# File 'lib/flicks/movie.rb', line 20 def total_snack_price @snacks_eaten.values.sum end |