Class: Assumption::ChartDataSet

Inherits:
Object
  • Object
show all
Defined in:
lib/assumption/chart_data_set.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year) ⇒ ChartDataSet

Returns a new instance of ChartDataSet.



16
17
18
19
20
21
# File 'lib/assumption/chart_data_set.rb', line 16

def initialize(year)
  @year = year
  @chart_song_array = Assumption::DataImporter.new(year).output
  @@all << self
  @last_choosen = nil
end

Instance Attribute Details

#chart_arrayObject

Returns the value of attribute chart_array.



14
15
16
# File 'lib/assumption/chart_data_set.rb', line 14

def chart_array
  @chart_array
end

#yearObject

Returns the value of attribute year.



14
15
16
# File 'lib/assumption/chart_data_set.rb', line 14

def year
  @year
end

Class Method Details

.allObject



10
11
12
# File 'lib/assumption/chart_data_set.rb', line 10

def self.all
  @@all
end

.find_or_create_by_year(year) ⇒ Object



5
6
7
8
# File 'lib/assumption/chart_data_set.rb', line 5

def self.find_or_create_by_year(year)
  var = self.all.find { |set| set.year == year}
  var ? var : Assumption::ChartDataSet.new(year)
end

Instance Method Details

#randomObject



23
24
25
26
27
28
29
30
# File 'lib/assumption/chart_data_set.rb', line 23

def random
  output = @chart_song_array.sample
  if output == @last_choosen
    self.random
  end
  @last_choosen = output
  output
end