Class: Gly::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/gly/document.rb

Overview

Result of parsing of a gly file. Usually contains one or more scores and possibly a document header.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



6
7
8
9
10
11
# File 'lib/gly/document.rb', line 6

def initialize
  @scores = []
  @scores_by_id = {}
  @header = Headers.new
  @path = nil
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



13
14
15
# File 'lib/gly/document.rb', line 13

def header
  @header
end

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/gly/document.rb', line 14

def path
  @path
end

#scoresObject (readonly)

Returns the value of attribute scores.



13
14
15
# File 'lib/gly/document.rb', line 13

def scores
  @scores
end

Instance Method Details

#<<(score) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gly/document.rb', line 16

def <<(score)
  @scores << score

  sid = score.headers['id']
  if sid
    if @scores_by_id.has_key? sid
      raise ArgumentError.new("More than one score with id '#{sid}'.")
    end

    @scores_by_id[sid] = score
  end

  self
end

#[](key) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/gly/document.rb', line 31

def [](key)
  if key.is_a? Integer
    @scores[key]
  else
    @scores_by_id[key]
  end
end