Class: Punctuated::Component
- Inherits:
-
Object
- Object
- Punctuated::Component
- Defined in:
- lib/punctuated/component.rb
Overview
A mutable parsed run. Setters delegate to Parsed so paired placements always remain coordinated.
Instance Attribute Summary collapse
-
#placement ⇒ Object
Returns the value of attribute placement.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#chars ⇒ Object
Whitespace is formatting owned by the run, not one of its punctuation characters.
-
#index ⇒ Object
The owner calculates this structurally, avoiding false matches when raw strings repeat.
-
#initialize(owner, side, raw = "", placement = nil) ⇒ Component
constructor
A new instance of Component.
- #kind ⇒ Object
Constructor Details
#initialize(owner, side, raw = "", placement = nil) ⇒ Component
Returns a new instance of Component.
10 11 12 13 14 |
# File 'lib/punctuated/component.rb', line 10 def initialize(owner, side, raw = "", placement = nil) @owner = owner @side = side commit(raw, placement) end |
Instance Attribute Details
#placement ⇒ Object
Returns the value of attribute placement.
8 9 10 |
# File 'lib/punctuated/component.rb', line 8 def placement @placement end |
#raw ⇒ Object
Returns the value of attribute raw.
8 9 10 |
# File 'lib/punctuated/component.rb', line 8 def raw @raw end |
Instance Method Details
#chars ⇒ Object
Whitespace is formatting owned by the run, not one of its punctuation characters.
25 26 27 |
# File 'lib/punctuated/component.rb', line 25 def chars @raw.each_char.reject { |character| WHITESPACE.match(character) } end |
#index ⇒ Object
The owner calculates this structurally, avoiding false matches when raw strings repeat.
30 31 32 33 34 |
# File 'lib/punctuated/component.rb', line 30 def index return -1 if @raw.empty? @owner.component_index(self) end |
#kind ⇒ Object
36 37 38 |
# File 'lib/punctuated/component.rb', line 36 def kind self.class::KIND end |