Class: Boilerpipe::Document::TextDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/boilerpipe/document/text_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, text_blocks) ⇒ TextDocument

Returns a new instance of TextDocument.



7
8
9
10
# File 'lib/boilerpipe/document/text_document.rb', line 7

def initialize(title, text_blocks)
  @text_blocks = text_blocks
  @title = title
end

Instance Attribute Details

#text_blocksObject (readonly)

Returns the value of attribute text_blocks.



4
5
6
# File 'lib/boilerpipe/document/text_document.rb', line 4

def text_blocks
  @text_blocks
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/boilerpipe/document/text_document.rb', line 5

def title
  @title
end

Instance Method Details

#contentObject



12
13
14
# File 'lib/boilerpipe/document/text_document.rb', line 12

def content
  text(true, false)
end

#debug_sObject Also known as: debug_string



39
40
41
# File 'lib/boilerpipe/document/text_document.rb', line 39

def debug_s
  @text_blocks.map(&:to_s).join("\n")
end

#replace_text_blocks!(new_blocks) ⇒ Object



35
36
37
# File 'lib/boilerpipe/document/text_document.rb', line 35

def replace_text_blocks!(new_blocks)
  @text_blocks = new_blocks
end

#text(include_content, include_noncontent) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/boilerpipe/document/text_document.rb', line 16

def text(include_content, include_noncontent)
  s = ''
  @text_blocks.each do |text_block|
    case text_block.is_content?
    when true
      next unless include_content

      s << text_block.text
      s << "\n"
    when false
      next unless include_noncontent

      s << text_block.text
      s << "\n"
    end
  end
  s
end