Class: TextExtractor::Directives::Group
- Inherits:
-
Object
- Object
- TextExtractor::Directives::Group
- Defined in:
- lib/text_extractor/directives/group.rb
Overview
a line group
Direct Known Subclasses
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #chomp(newline) ⇒ Object
- #finish(newline) ⇒ Object
-
#initialize(type, *args) ⇒ Group
constructor
A new instance of Group.
- #join ⇒ Object
- #to_a ⇒ Object
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 |
#join ⇒ Object
34 35 36 |
# File 'lib/text_extractor/directives/group.rb', line 34 def join ["(#{@type}", *@lines, ')'] end |
#to_a ⇒ Object
14 15 16 |
# File 'lib/text_extractor/directives/group.rb', line 14 def to_a @lines end |