class Focus::Movie
Attributes
rank[RW]
snack_carbs[R]
title[R]
Public Class Methods
convert(line)
click to toggle source
# File lib/focus/movie.rb, line 16 def self.convert(line) title,rank = line.split(',') Movie.new(title,Integer(rank)) end
new(title, rank=0)
click to toggle source
# File lib/focus/movie.rb, line 10 def initialize(title, rank=0) @title = title.capitalize @rank = rank @snack_carbs = Hash.new(0) end
Public Instance Methods
ate_snack(snack)
click to toggle source
# File lib/focus/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()
click to toggle source
# File lib/focus/movie.rb, line 28 def carbs_consumed @snack_carbs.values.reduce(0) {|sum,snack| sum + snack } # @snacks_carbs.values.reduce(0,:+) end
expose_hash() { |snack| ... }
click to toggle source
# File lib/focus/movie.rb, line 21 def expose_hash @snack_carbs.each do |key,value| snack = Snack.new(key,value.to_i) yield(snack) end end
title=(title)
click to toggle source
# File lib/focus/movie.rb, line 39 def title=(title) @title = title.capitalize end
to_s()
click to toggle source
# File lib/focus/movie.rb, line 43 def to_s "#{@title} with a rank of #{@rank} (#{status})" end