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
12
# File 'lib/gly/document.rb', line 6

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

Instance Attribute Details

#contentObject (readonly)

Scores and Markups



18
19
20
# File 'lib/gly/document.rb', line 18

def content
  @content
end

#headerObject (readonly)

Returns the value of attribute header.



20
21
22
# File 'lib/gly/document.rb', line 20

def header
  @header
end

#pathObject

Returns the value of attribute path.



21
22
23
# File 'lib/gly/document.rb', line 21

def path
  @path
end

#scoresObject (readonly)

only Scores



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

def scores
  @scores
end

Instance Method Details

#<<(score) ⇒ Object

append a new Score (or Markup)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gly/document.rb', line 24

def <<(score)
  @content << score

  if score.is_a? 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
  end

  self
end

#[](key) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/gly/document.rb', line 43

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