class Acme::Smileage::Discography::Sales
Attributes
first_week_sales[R]
peak_rank[R]
total_sales[R]
weeks_on_chart[R]
Public Class Methods
new(first_week_sales, total_sales, peak_rank, weeks_on_chart)
click to toggle source
# File lib/acme/smileage/discography/sales.rb, line 22 def initialize(first_week_sales, total_sales, peak_rank, weeks_on_chart) @first_week_sales = first_week_sales @total_sales = total_sales @peak_rank = peak_rank @weeks_on_chart = weeks_on_chart end
records(*records)
click to toggle source
# File lib/acme/smileage/discography/sales.rb, line 9 def self.records(*records) if records.empty? return self.new(0, 0, 0, 0) end first_week_sales = records[0][:sales] total_sales = records.inject(0){|acc,e| acc + e[:sales] } peak_rank = records.map{|e| e[:rank] }.min weeks_on_chart = records.length self.new(first_week_sales, total_sales, peak_rank, weeks_on_chart) end
Public Instance Methods
first_week_to_total_ratio()
click to toggle source
# File lib/acme/smileage/discography/sales.rb, line 29 def first_week_to_total_ratio self.total_sales.zero? ? 0 : self.first_week_sales.to_f / self.total_sales.to_f end
to_a()
click to toggle source
# File lib/acme/smileage/discography/sales.rb, line 37 def to_a [self.first_week_sales, self.total_sales, self.peak_rank, self.weeks_on_chart] end
total_to_first_week_ratio()
click to toggle source
# File lib/acme/smileage/discography/sales.rb, line 33 def total_to_first_week_ratio self.first_week_sales.zero? ? 0 : self.total_sales.to_f / self.first_week_sales.to_f end