Class: Traktor::NML::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/traktor/nml/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Collection

Returns a new instance of Collection.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/traktor/nml/collection.rb', line 13

def initialize(node)
  @collection = node.map do |el|
    Traktor::NML::Track.new({
      title: try_text(el.attribute('TITLE')),
      artist: try_text(el.attribute('ARTIST')),
      album: {
        title: el.xpath('ALBUM[@TITLE]').attribute('TITLE').map{ |e| e.text }.join(", "),
        track: try_text(el.xpath('ALBUM[@TRACK]').attribute('TRACK').first),
      },
      primarykey: el.xpath('LOCATION').map { |loc|
        loc.attribute('VOLUME').text + loc.attribute('DIR').text + loc.attribute('FILE').text
      }.first,
      genre: el.xpath('INFO[@GENRE]').attribute('GENRE').map{ |e| e.text }.join(", "),
      label: el.xpath('INFO[@LABEL]').attribute('LABEL').map{ |e| e.text }.join(", "),
      playtime: el.xpath('INFO[@PLAYTIME]').attribute('PLAYTIME').map{ |e| e.text.to_f }.first,
      release_date: parse_date(el.xpath('INFO[@RELEASE_DATE]').attribute('RELEASE_DATE').map{ |e| e.text }.join(", ")),
      bpm: el.xpath('TEMPO[@BPM]').attribute('BPM').map{ |e| e.text.to_f }.first,
      key: try_text(el.xpath('INFO[@KEY]').attribute('KEY').first),
      musical_key: try_text(el.xpath('MUSICAL_KEY[@VALUE]').attribute('VALUE').first),
      cues: el.xpath('CUE_V2').map do |cue|
        Traktor::NML::Cue.new({
          name: cue.attribute('NAME').value,
          type: cue.attribute('TYPE').value.to_i,
          start: cue.attribute('START').value.to_f,
          length: cue.attribute('LEN').value.to_f,
          repeats: cue.attribute('REPEATS').value.to_i,
          hotcue: cue.attribute('HOTCUE').value.to_i
        })
      end
    })
  end
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



11
12
13
# File 'lib/traktor/nml/collection.rb', line 11

def collection
  @collection
end

Instance Method Details

#[](i) ⇒ Object



63
64
65
# File 'lib/traktor/nml/collection.rb', line 63

def [](i)
  @collection[i]
end

#eachObject



57
58
59
60
61
# File 'lib/traktor/nml/collection.rb', line 57

def each
  @collection.each do |track|
    yield track
  end
end

#lengthObject Also known as: size



52
53
54
# File 'lib/traktor/nml/collection.rb', line 52

def length
  @collection.length
end

#track_from_primarykey(primarykey) ⇒ Object



46
47
48
49
50
# File 'lib/traktor/nml/collection.rb', line 46

def track_from_primarykey(primarykey)
  @collection.find do |track|
    track.primarykey == primarykey
  end
end