Class: MusicalScore::Score::Identification::Encoding
- Inherits:
-
ElementBase
- Object
- ElementBase
- MusicalScore::Score::Identification::Encoding
- Includes:
- Contracts
- Defined in:
- lib/musical_score/score/identification/encoding.rb
Instance Attribute Summary collapse
-
#encoding_date ⇒ Object
readonly
Returns the value of attribute encoding_date.
-
#encoding_description ⇒ Object
readonly
Returns the value of attribute encoding_description.
-
#softwares ⇒ Object
readonly
Returns the value of attribute softwares.
-
#supports ⇒ Object
readonly
Returns the value of attribute supports.
Class Method Summary collapse
Instance Method Summary collapse
- #export_xml ⇒ Object
-
#initialize(encoding_date, encoding_description, softwares, supports) ⇒ Encoding
constructor
A new instance of Encoding.
Constructor Details
#initialize(encoding_date, encoding_description, softwares, supports) ⇒ Encoding
Returns a new instance of Encoding.
11 12 13 14 15 16 |
# File 'lib/musical_score/score/identification/encoding.rb', line 11 def initialize(encoding_date, encoding_description, softwares, supports) @encoding_date = encoding_date @encoding_description = encoding_description @softwares = softwares @supports = supports end |
Instance Attribute Details
#encoding_date ⇒ Object (readonly)
Returns the value of attribute encoding_date.
9 10 11 |
# File 'lib/musical_score/score/identification/encoding.rb', line 9 def encoding_date @encoding_date end |
#encoding_description ⇒ Object (readonly)
Returns the value of attribute encoding_description.
9 10 11 |
# File 'lib/musical_score/score/identification/encoding.rb', line 9 def encoding_description @encoding_description end |
#softwares ⇒ Object (readonly)
Returns the value of attribute softwares.
9 10 11 |
# File 'lib/musical_score/score/identification/encoding.rb', line 9 def softwares @softwares end |
#supports ⇒ Object (readonly)
Returns the value of attribute supports.
9 10 11 |
# File 'lib/musical_score/score/identification/encoding.rb', line 9 def supports @supports end |
Class Method Details
.create_by_hash(doc) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/musical_score/score/identification/encoding.rb', line 40 def self.create_by_hash(doc) encoding_date = Time.new if (doc.has_key?("encoding-date")) encoding_date = Time.parse(doc["encoding-date"][0]) end encoding_description = doc.has_key?("encoding_description") ? doc["encoding_date"] : '' softwares = Array.new if doc.has_key?("software") doc["software"].each do |element| softwares.push(element) end end supports = Array.new doc["supports"].each do |element| if (element["type"] == "yes") supports.push(element["element"]) end end return MusicalScore::Score::Identification::Encoding.new(encoding_date, encoding_description, softwares, supports) end |
.create_by_xml(xml_doc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/musical_score/score/identification/encoding.rb', line 19 def self.create_by_xml(xml_doc) encoding_date = Time.new if (xml_doc.elements["//encoding-date"]) encoding_date = Time.parse(xml_doc.elements["//encoding-date"].text) end encoding_description = xml_doc.elements["//encoding-description"] ? xml_doc.elements["//encoding_description"].text : '' softwares = Array.new xml_doc.elements.each("//software") do |element| softwares.push(element.text) end supports = Array.new xml_doc.elements.each("//supports") do |element| if (element.attributes["type"] == "yes") supports.push(element.attributes["element"]) end end return MusicalScore::Score::Identification::Encoding.new(encoding_date, encoding_description, softwares, supports) end |
Instance Method Details
#export_xml ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/musical_score/score/identification/encoding.rb', line 61 def export_xml encoding = REXML::Element.new('encoding') @softwares.each do |software| software_e = REXML::Element.new('software') software_e.add_text(software) encoding.add_element(software_e) end encoding_date = REXML::Element.new('encoding-date') encoding_date.add_text(@encoding_date.strftime("%Y-%m-%d")) encoding.add_element(encoding_date) @supports.each do |support| supports_e = REXML::Element.new('supports') supports_e.add_attribute('type','yes') supports_e.add_attribute('element',support) encoding.add_element(supports_e) end desc_e = REXML::Element.new('encoding-description') if (@encoding_description != '') desc_e.add_text(@encoding_description) encoding.add_element(desc_e) end return encoding end |