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.



16
17
18
19
20
# File 'lib/looperman_samples/sample.rb', line 16

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

extend Concerns::Findable responsible for knowing about all of the samples



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

def bpm
  @bpm
end

#creatorObject

extend Concerns::Findable responsible for knowing about all of the samples



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

def creator
  @creator
end

#download_countObject

extend Concerns::Findable responsible for knowing about all of the samples



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

def download_count
  @download_count
end

#genreObject

extend Concerns::Findable responsible for knowing about all of the samples



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

def genre
  @genre
end

#keyObject

extend Concerns::Findable responsible for knowing about all of the samples



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

def key
  @key
end

#titleObject

extend Concerns::Findable responsible for knowing about all of the samples



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

def title
  @title
end

#urlObject

extend Concerns::Findable responsible for knowing about all of the samples



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

def url
  @url
end

Class Method Details

.allObject



12
13
14
# File 'lib/looperman_samples/sample.rb', line 12

def self.all
  @@all
end

.list_samples_by_download_countObject



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

def self.list_samples_by_download_count
  #sort the samples by download count and return as a numbered list
  samples_sorted_by_download_count = LoopermanSamples::Sample.all.sort {|a, b| b.download_count.to_i <=> a.download_count.to_i}
  samples_sorted_by_download_count.each_with_index do |item, index|
  puts "#{index + 1}." + " #{item.title}" + " - #{item.download_count} downloads"
end
end

.list_samples_by_keyObject



32
33
34
35
36
37
38
# File 'lib/looperman_samples/sample.rb', line 32

def self.list_samples_by_key
  #sort the samples by key and return as a numbered list
  samples_sorted_by_key = LoopermanSamples::Sample.all.sort {|a, b| a.key <=> b.key}
  samples_sorted_by_key.each_with_index do |item, index|
    puts "#{index + 1}." + " #{item.title} - " + "#{item.key}"
  end
end

.list_samples_by_tempoObject



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

def self.list_samples_by_tempo
  #sort the samples by tempo(bpm) and return as a numbered list
  samples_sorted_by_tempo = LoopermanSamples::Sample.all.sort {|a, b| b.bpm.to_i <=> a.bpm.to_i}
  samples_sorted_by_tempo.each_with_index do |item, index|
  puts "#{index + 1}." + " #{item.title}" + "- #{item.bpm}"
end
end