Class: TextExtractor::Directives::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/text_extractor/directives/group.rb

Overview

a line group

Direct Known Subclasses

AnyGroup, CaptureGroup

Instance Method Summary collapse

Constructor Details

#initialize(type, *args) ⇒ Group

Returns a new instance of Group.



5
6
7
8
# File 'lib/text_extractor/directives/group.rb', line 5

def initialize(type, *args)
  @type = type
  @lines = args
end

Instance Method Details

#<<(item) ⇒ Object



10
11
12
# File 'lib/text_extractor/directives/group.rb', line 10

def <<(item)
  @lines << item
end

#chomp(newline) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/text_extractor/directives/group.rb', line 18

def chomp(newline)
  return if @lines.empty? || newline
  tail = @lines[-1]
  if tail.is_a?(Array)
    tail = tail[-1] while tail[-1].is_a?(Array)
    tail[-2] = tail[-2].chomp
  else
    @lines[-1] = @lines[-1].chomp
  end
end

#finish(newline) ⇒ Object



29
30
31
32
# File 'lib/text_extractor/directives/group.rb', line 29

def finish(newline)
  chomp(newline)
  join
end

#joinObject



34
35
36
# File 'lib/text_extractor/directives/group.rb', line 34

def join
  ["(#{@type}", *@lines, ')']
end

#to_aObject



14
15
16
# File 'lib/text_extractor/directives/group.rb', line 14

def to_a
  @lines
end