Class: LoopermanSamples::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/looperman_samples/sample.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, creator = nil, genre = nil) ⇒ Sample

Returns a new instance of Sample.



13
14
15
16
17
# File 'lib/looperman_samples/sample.rb', line 13

def initialize(title = nil, creator = nil, genre = nil)
  @title = title
  self.creator = creator if creator
  self.genre = genre if genre
end

Instance Attribute Details

#bpmObject

Returns the value of attribute bpm.



6
7
8
# File 'lib/looperman_samples/sample.rb', line 6

def bpm
  @bpm
end

#creatorObject

Returns the value of attribute creator.



6
7
8
# File 'lib/looperman_samples/sample.rb', line 6

def creator
  @creator
end

#download_countObject

Returns the value of attribute download_count.



6
7
8
# File 'lib/looperman_samples/sample.rb', line 6

def download_count
  @download_count
end

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/looperman_samples/sample.rb', line 6

def key
  @key
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/looperman_samples/sample.rb', line 6

def title
  @title
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/looperman_samples/sample.rb', line 6

def url
  @url
end

Class Method Details

.allObject



9
10
11
# File 'lib/looperman_samples/sample.rb', line 9

def self.all
  @@all
end

.list_samples_by_download_countObject



50
51
52
53
54
55
# File 'lib/looperman_samples/sample.rb', line 50

def self.list_samples_by_download_count
  sort_by_download_count.each_with_index do |item, index|
    #get rid of this! puts shouldn't be in sample class
    puts "#{index + 1}." + " #{item.title}" + " - #{item.download_count} downloads"
  end
end

.list_samples_by_keyObject



28
29
30
31
32
33
# File 'lib/looperman_samples/sample.rb', line 28

def self.list_samples_by_key
  sort_by_key.each_with_index do |item, index|
    #get rid of this! puts shouldn't be in sample class
    puts "#{index + 1}." + " #{item.title} - " + "#{item.key}"
  end
end

.list_samples_by_tempoObject



39
40
41
42
43
44
# File 'lib/looperman_samples/sample.rb', line 39

def self.list_samples_by_tempo
  sort_by_tempo.each_with_index do |item, index|
    #get rid of this! puts shouldn't be in sample class
    puts "#{index + 1}." + " #{item.title}" + "- #{item.bpm}"
  end
end

.sort_by_download_countObject



46
47
48
# File 'lib/looperman_samples/sample.rb', line 46

def self.sort_by_download_count
  all.sort{|a, b| b.download_count.to_i <=> a.download_count.to_i}
end

.sort_by_keyObject



24
25
26
# File 'lib/looperman_samples/sample.rb', line 24

def self.sort_by_key
  all.sort{|a, b| a.key <=> b.key}
end

.sort_by_tempoObject



35
36
37
# File 'lib/looperman_samples/sample.rb', line 35

def self.sort_by_tempo
  all.sort{|a, b| b.bpm.to_i <=> a.bpm.to_i}
end