Class: MusicalScore::Attribute::Time
- Inherits:
-
ElementBase
- Object
- ElementBase
- MusicalScore::Attribute::Time
- Includes:
- Contracts
- Defined in:
- lib/musical_score/attribute/time.rb
Instance Attribute Summary collapse
-
#beat_type ⇒ Object
readonly
Returns the value of attribute beat_type.
-
#beats ⇒ Object
readonly
Returns the value of attribute beats.
Class Method Summary collapse
Instance Method Summary collapse
- #export_xml ⇒ Object
-
#initialize(beats, beat_type) ⇒ Time
constructor
A new instance of Time.
-
#to_s ⇒ String
Describe the time object in a fraction style.
Constructor Details
#initialize(beats, beat_type) ⇒ Time
Returns a new instance of Time.
11 12 13 14 |
# File 'lib/musical_score/attribute/time.rb', line 11 def initialize(beats, beat_type) @beats = beats @beat_type = beat_type end |
Instance Attribute Details
#beat_type ⇒ Object (readonly)
Returns the value of attribute beat_type.
6 7 8 |
# File 'lib/musical_score/attribute/time.rb', line 6 def beat_type @beat_type end |
#beats ⇒ Object (readonly)
Returns the value of attribute beats.
6 7 8 |
# File 'lib/musical_score/attribute/time.rb', line 6 def beats @beats end |
Class Method Details
.create_by_hash(doc) ⇒ Object
29 30 31 32 33 |
# 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) ⇒ Object
22 23 24 25 26 |
# 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 |
Instance Method Details
#export_xml ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ String
Returns describe the time object in a fraction style.
17 18 19 |
# File 'lib/musical_score/attribute/time.rb', line 17 def to_s return "%d/%d" % [@beats, @beat_type] end |