Class: TextExtractor::Directives
- Inherits:
-
Object
- Object
- TextExtractor::Directives
- Defined in:
- lib/text_extractor/directives.rb,
lib/text_extractor/directives/group.rb,
lib/text_extractor/directives/classes.rb
Overview
Directives can only be named with lowercase ascii letters (a-z) and _ (underscore).
Directives can take an argument. An argument can contain any sequence of characters other than newlines, parenthesis, or dot (.). The argument appears after the name, in parenthesis, with no whitespace between the name and left parenthesis. Whitespace inside the parenthesis is taken literally and not ignored.
When used, each directive name is preceeded by a dot (.). There should be no whitespace on either side of the dot. Some directives can be chained one after another, still using a dot to separate the earlier directive from the later one.
Defined Under Namespace
Classes: Any, AnyGroup, Begin, Capture, CaptureGroup, Comment, Directive, End, Group, Maybe, Repeat, Rest
Instance Method Summary collapse
- #expand ⇒ Object
-
#initialize(original) ⇒ Directives
constructor
A new instance of Directives.
- #values ⇒ Object
Constructor Details
#initialize(original) ⇒ Directives
Returns a new instance of Directives.
25 26 27 28 29 30 |
# File 'lib/text_extractor/directives.rb', line 25 def initialize(original) @source = original.source = original. @output = nil @directives = [] end |
Instance Method Details
#expand ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/text_extractor/directives.rb', line 32 def return @output if @output @state = State.new scanner = StringScanner.new(@source) read_line(scanner) until scanner.eos? raise 'Unterminated line group' unless @state.groups.empty? @output = Regexp.new(@state.target.join(''), ) end |
#values ⇒ Object
41 42 43 |
# File 'lib/text_extractor/directives.rb', line 41 def values @directives.flat_map(&:values) end |