class MusicalScore::Attribute::Time

Attributes

beat_type[R]
beats[R]

Public Class Methods

create_by_hash(doc) click to toggle source
# File lib/musical_score/attribute/time.rb, line 29
def self.create_by_hash(doc)
    beats     = doc["beats"][0].to_i
    beat_type = doc["beat-type"][0].to_i
    return MusicalScore::Attribute::Time.new(beats, beat_type)
end
create_by_xml(xml_doc) click to toggle source
# File lib/musical_score/attribute/time.rb, line 22
def self.create_by_xml(xml_doc)
    beats     = xml_doc.elements["beats"].text.to_i
    beat_type = xml_doc.elements["beat-type"].text.to_i
    return MusicalScore::Attribute::Time.new(beats, beat_type)
end
new(beats, beat_type) click to toggle source
# File lib/musical_score/attribute/time.rb, line 11
def initialize(beats, beat_type)
    @beats     = beats
    @beat_type = beat_type
end

Public Instance Methods

export_xml() click to toggle source
# File lib/musical_score/attribute/time.rb, line 35
def export_xml
    time      = REXML::Element.new('time')
    beats     = REXML::Element.new('beats')
    beat_type = REXML::Element.new('beat-type')

    beats.add_text(@beats.to_s)
    beat_type.add_text(@beat_type.to_s)

    time.add_element(beats)
    time.add_element(beat_type)

    return time
end
to_s() click to toggle source

@return [String] describe the time object in a fraction style

# File lib/musical_score/attribute/time.rb, line 17
def to_s
    return "%d/%d" % [@beats, @beat_type]
end