Class: HeadMusic::Content::Comment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#compositionObject (readonly)

Returns the value of attribute composition.



6
7
8
# File 'lib/head_music/content/comment.rb', line 6

def composition
  @composition
end

#positionObject (readonly)

Returns the value of attribute position.



6
7
8
# File 'lib/head_music/content/comment.rb', line 6

def position
  @position
end

#textObject (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_sObject



14
15
16
# File 'lib/head_music/content/comment.rb', line 14

def to_s
  text
end