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

#<=>, #hit?, #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/flicks/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.



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

def rank
  @rank
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



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

def self.from_csv(line)
  title, rank = line.split(",")
  Movie.new(title, Integer(rank))
end

Instance Method Details

#ate_snack(snack) ⇒ Object



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

def ate_snack(snack)
  @snack_carbs[snack.name] += snack.carbs
  puts "#{@title} led to #{snack.carbs} #{snack.name} carbs being consumed."
  puts "#{@title}'s snacks: #{@snack_carbs}"
end

#carbs_consumedObject



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

def carbs_consumed
  @snack_carbs.values.reduce(0, :+)
end

#each_snackObject



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

def each_snack
  @snack_carbs.each do |name, carbs|
    snack = Snack.new(name, carbs)
    yield snack
  end
end

#to_csvObject



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

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

#to_sObject



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

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