Class: MusicalScore::Part::Measure
- Inherits:
-
ElementBase
- Object
- ElementBase
- MusicalScore::Part::Measure
- Includes:
- Contracts
- Defined in:
- lib/musical_score/part/measure.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#length ⇒ Object
Returns the value of attribute length.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Class Method Summary collapse
Instance Method Summary collapse
- #export_xml ⇒ Object
-
#initialize(notes, number, attribute = nil) ⇒ Measure
constructor
A new instance of Measure.
- #location ⇒ Object
Constructor Details
#initialize(notes, number, attribute = nil) ⇒ Measure
Returns a new instance of Measure.
12 13 14 15 16 |
# File 'lib/musical_score/part/measure.rb', line 12 def initialize(notes, number, attribute = nil) @notes = notes @number = number @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
9 10 11 |
# File 'lib/musical_score/part/measure.rb', line 9 def attribute @attribute end |
#length ⇒ Object
Returns the value of attribute length.
10 11 12 |
# File 'lib/musical_score/part/measure.rb', line 10 def length @length end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
9 10 11 |
# File 'lib/musical_score/part/measure.rb', line 9 def notes @notes end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
9 10 11 |
# File 'lib/musical_score/part/measure.rb', line 9 def number @number end |
Class Method Details
.create_by_hash(doc) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/musical_score/part/measure.rb', line 33 def self.create_by_hash(doc) number = doc["number"].to_i attributes = doc.has_key?("attributes") ? MusicalScore::Attribute::Attribute.create_by_hash(doc["attributes"][0]) : nil note_array = Array.new doc["note"].each do |element| note = MusicalScore::Note::Note.create_by_hash(element) note_array.push(note) end notes = MusicalScore::Notes.new(note_array) return MusicalScore::Part::Measure.new(notes, number, attributes) end |
.create_by_xml(xml_doc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/musical_score/part/measure.rb', line 19 def self.create_by_xml(xml_doc) attribute_doc = xml_doc.elements["//attributes"] attributes = attribute_doc ? MusicalScore::Attribute::Attribute.create_by_xml(attribute_doc) : nil number = xml_doc.attributes["number"].to_i note_array = Array.new xml_doc.elements.each("//note") do |element| note = MusicalScore::Note::Note.create_by_xml(element) note_array.push(note) end notes = MusicalScore::Notes.new(note_array) return MusicalScore::Part::Measure.new(notes, number, attributes) end |
Instance Method Details
#export_xml ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/musical_score/part/measure.rb', line 45 def export_xml measure_element = REXML::Element.new('measure') measure_element.add_attribute('number',@number.to_s) measure_element.add_element(@attribute.export_xml) if @attribute @notes.each do |note| measure_element.add_element(note.export_xml) end return measure_element end |
#location ⇒ Object
57 58 59 |
# File 'lib/musical_score/part/measure.rb', line 57 def location return @notes[0].location end |