Class: Squeezer::Models::Model

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

Direct Known Subclasses

Album, Artist, Genre, Player, Playlist, Track

Class Method Summary collapse

Methods inherited from API

#initialize

Methods included from Connection

close_connection, exec, #exit, open_connection, retrieve_connection

Constructor Details

This class inherits a constructor from Squeezer::API

Class Method Details

.extract_records(data) ⇒ Object

update regex to play nice with : chars



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/squeezer/models.rb', line 7

def self.extract_records(data)
  records = Array.new
  record = Hash.new
  data.scan(/([^\s]+)%3A([^\s]+)/) do |match|
    if match[0] == "id"
      records << record unless record.empty?
      record = {:id => URI.unescape(match[1])}
    end
    record[match[0].to_sym] = URI.unescape(match[1]) unless record.empty?
  end
  record.delete(:count)
  records << record unless record.empty?
  records
end