Class: HeadMusic::Content::Comment
- Inherits:
-
Object
- Object
- HeadMusic::Content::Comment
- Defined in:
- lib/head_music/content/comment.rb
Overview
A comment is a free-text annotation, optionally anchored to a position in a composition.
Instance Attribute Summary collapse
-
#composition ⇒ Object
readonly
Returns the value of attribute composition.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#ensure_position(position) ⇒ Object
private
-
#initialize(composition, text, position = nil) ⇒ Comment
constructor
A new instance of Comment.
-
#to_s ⇒ Object
Constructor Details
#initialize(composition, text, position = nil) ⇒ Comment
Returns a new instance of Comment.
8 9 10 11 12 |
# File 'lib/head_music/content/comment.rb', line 8 def initialize(composition, text, position = nil) @composition = composition @text = text ensure_position(position) end |
Instance Attribute Details
#composition ⇒ Object (readonly)
Returns the value of attribute composition.
6 7 8 |
# File 'lib/head_music/content/comment.rb', line 6 def composition @composition end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
6 7 8 |
# File 'lib/head_music/content/comment.rb', line 6 def position @position end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/head_music/content/comment.rb', line 6 def text @text end |
Instance Method Details
#ensure_position(position) ⇒ Object (private)
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/head_music/content/comment.rb', line 20 def ensure_position(position) return if position.nil? @position = if position.is_a?(HeadMusic::Content::Position) unless position.composition.equal?(composition) raise ArgumentError, "position belongs to a different composition" end position else HeadMusic::Content::Position.new(composition, position) end end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/head_music/content/comment.rb', line 14 def to_s text end |