Class: Flicks::Movie

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

Direct Known Subclasses

Movie3D

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rankable

#thumbs_down, #thumbs_up

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

#rankObject

Returns the value of attribute rank.



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

def rank
  @rank
end

#snacks_eatenObject (readonly)

Returns the value of attribute snacks_eaten.



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

def snacks_eaten
  @snacks_eaten
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.from_csv(line) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/flicks/movie.rb', line 24

def self.from_csv(line)
  title, rank = line.split(",")
  Movie.new(title, Integer(rank))
rescue ArgumentError
  puts "Ignored invalid rank: #{rank}"
  Movie.new(title)
end

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_csvObject



32
33
34
# File 'lib/flicks/movie.rb', line 32

def to_csv
  "#{@title},#{@rank}"
end

#to_sObject



36
37
38
# File 'lib/flicks/movie.rb', line 36

def to_s
  "#{@title} has a rank of #{@rank}"
end

#total_snack_priceObject



20
21
22
# File 'lib/flicks/movie.rb', line 20

def total_snack_price
  @snacks_eaten.values.sum
end