Class: Deba::Document

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

Constant Summary collapse

BLOCKQUOTE =
"> "

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extractor) ⇒ Document

Returns a new instance of Document.



6
7
8
9
10
11
# File 'lib/deba/document.rb', line 6

def initialize(extractor)
  @extractor = extractor
  @content = ""

  start
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

Instance Method Details

#<<(segment) ⇒ Object



13
14
15
# File 'lib/deba/document.rb', line 13

def <<(segment)
  @segments << segment
end

#break(*args) ⇒ Object



17
18
19
20
# File 'lib/deba/document.rb', line 17

def break(*args)
  finish
  start(*args)
end

#finishObject



22
23
24
25
26
27
28
29
30
# File 'lib/deba/document.rb', line 22

def finish
  return unless present?

  @args.unshift(@segments)
  block = @block_type.new(*@args).to_a
  block.unshift(BLOCKQUOTE) if @extractor.in_blockquote?

  @content << Deba::Stringifier.new(block).stringify
end

#present?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/deba/document.rb', line 38

def present?
  @segments.any? { |segment| segment.is_a?(Deba::Span) && Deba::Utils.present?(segment.to_s) }
end

#start(*args) ⇒ Object



32
33
34
35
36
# File 'lib/deba/document.rb', line 32

def start(*args)
  @segments = []
  @block_type = args.shift
  @args = args
end