Class: Punctuated::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/punctuated/component.rb

Overview

A mutable parsed run. Setters delegate to Parsed so paired placements always remain coordinated.

Direct Known Subclasses

Terminal, Wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#placementObject

Returns the value of attribute placement.



8
9
10
# File 'lib/punctuated/component.rb', line 8

def placement
  @placement
end

#rawObject

Returns the value of attribute raw.



8
9
10
# File 'lib/punctuated/component.rb', line 8

def raw
  @raw
end

Instance Method Details

#charsObject

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

#indexObject

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

#kindObject



36
37
38
# File 'lib/punctuated/component.rb', line 36

def kind
	self.class::KIND
end