Class: Squeezer::Models::Genre

Inherits:
Model
  • Object
show all
Defined in:
lib/squeezer/models/genre.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

extract_records

Methods included from Connection

close_connection, exec, #exit, open_connection, retrieve_connection

Constructor Details

#initialize(record) ⇒ Genre

Returns a new instance of Genre.



7
8
9
10
11
12
# File 'lib/squeezer/models/genre.rb', line 7

def initialize(record)
  unless record.nil?
    @id = record[:id] if record.key?(:id)
    @name = record[:genre] if record.key?(:genre)
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/squeezer/models/genre.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/squeezer/models/genre.rb', line 5

def name
  @name
end

Class Method Details

.allObject



18
19
20
21
22
23
24
# File 'lib/squeezer/models/genre.rb', line 18

def self.all
  results = Array.new
  Model.extract_records(Connection.exec("genres 0 #{total} charset:utf8 tags:s")).each do |record|
    results << Genre.new(record)
  end
  results
end

.totalObject



14
15
16
# File 'lib/squeezer/models/genre.rb', line 14

def self.total
  Connection.exec("info total genres ?").to_i
end