Class: Punctuated::Parsed
- Inherits:
-
Object
- Object
- Punctuated::Parsed
- Includes:
- Composition, Operations, Parsing
- Defined in:
- lib/punctuated/parsed.rb,
lib/punctuated/parsed/parsing.rb,
lib/punctuated/parsed/operations.rb,
lib/punctuated/parsed/composition.rb
Overview
Holds a decomposed string while focused concerns parse, inspect and transform its state.
Defined Under Namespace
Modules: Composition, Operations, Parsing
Constant Summary collapse
- DEFAULT_TERMINALS =
".".freeze
- KINDS =
[:terminal, :wrapper].freeze
Constants included from Operations
Operations::METHODS, Operations::METHOD_SIDES, Operations::QUERY_METHODS, Operations::TRANSFORMING_METHODS
Instance Attribute Summary collapse
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#terminals ⇒ Object
readonly
Returns the value of attribute terminals.
-
#wrappers ⇒ Object
readonly
Returns the value of attribute wrappers.
Instance Method Summary collapse
-
#component(side, kind) ⇒ Object
Internal access is public for collaborating Component instances, but is not part of the documented API.
- #content ⇒ Object
- #content=(value) ⇒ Object
-
#initialize(string, options = nil, **keywords) ⇒ Parsed
constructor
A new instance of Parsed.
- #initialize_copy(source) ⇒ Object
Methods included from Operations
#end_with?, #ensure!, #ensure_start!, #lstrip!, #replace!, #rstrip!, #start_with?, #strip!
Methods included from Composition
#change_component, #component_index, #result
Constructor Details
#initialize(string, options = nil, **keywords) ⇒ Parsed
Returns a new instance of Parsed.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/punctuated/parsed.rb', line 21 def initialize(string, = nil, **keywords) settings = Options.hash(, keywords, allowed: [:side, :wrappers, :terminals], label: "parse options") if settings.key?(:wrappers) && settings.key?(:terminals) raise ArgumentError, "wrappers and terminals placement constraints are mutually exclusive" end @side_mode = settings.key?(:side) ? Options.side(settings[:side]) : nil @wrapper_constraints = parse_constraints(settings, :wrappers) @terminal_constraints = parse_constraints(settings, :terminals) build_components parse_string(string) end |
Instance Attribute Details
#original ⇒ Object (readonly)
Returns the value of attribute original.
19 20 21 |
# File 'lib/punctuated/parsed.rb', line 19 def original @original end |
#terminals ⇒ Object (readonly)
Returns the value of attribute terminals.
19 20 21 |
# File 'lib/punctuated/parsed.rb', line 19 def terminals @terminals end |
#wrappers ⇒ Object (readonly)
Returns the value of attribute wrappers.
19 20 21 |
# File 'lib/punctuated/parsed.rb', line 19 def wrappers @wrappers end |
Instance Method Details
#component(side, kind) ⇒ Object
Internal access is public for collaborating Component instances, but is not part of the documented API.
63 64 65 |
# File 'lib/punctuated/parsed.rb', line 63 def component(side, kind) kind == :terminal ? @terminals[side] : @wrappers[side] end |
#content ⇒ Object
50 51 52 |
# File 'lib/punctuated/parsed.rb', line 50 def content @content end |
#content=(value) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/punctuated/parsed.rb', line 54 def content=(value) unless value.is_a?(String) raise ArgumentError, "content must be a String" end @content = value end |
#initialize_copy(source) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/punctuated/parsed.rb', line 34 def initialize_copy(source) super @original = source.original.dup.freeze @content = source.content.dup @side_mode = source.instance_variable_get(:@side_mode) @wrapper_constraints = source.instance_variable_get(:@wrapper_constraints).dup @terminal_constraints = source.instance_variable_get(:@terminal_constraints).dup build_components 2.times do |side| KINDS.each do |kind| source_component = source.component(side, kind) component(side, kind).__send__(:commit, source_component.raw, source_component.placement) end end end |