Class: YDocx::Parser

Inherits:
Object
  • Object
show all
Includes:
MarkupMethod
Defined in:
lib/ydocx/parser.rb,
lib/ydocx/templates/patinfo.rb,
lib/ydocx/templates/fachinfo.rb

Constant Summary collapse

@@figure_pattern =
/‘|’|'|´/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MarkupMethod

#markup

Constructor Details

#initialize(doc, rel) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ydocx/parser.rb', line 12

def initialize(doc, rel)
  @doc = Nokogiri::XML.parse(doc)
  @rel = Nokogiri::XML.parse(rel)
  @coder = HTMLEntities.new
  @indecies = []
  @images = []
  @result = []
  @space = ' '
  @image_path = 'images'
  @image_style = ''
  init
  if block_given?
    yield self
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/ydocx/templates/fachinfo.rb', line 8

def code
  @code
end

#imagesObject

Returns the value of attribute images.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def images
  @images
end

#indeciesObject

Returns the value of attribute indecies.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def indecies
  @indecies
end

#langObject

Returns the value of attribute lang.



8
9
10
# File 'lib/ydocx/templates/fachinfo.rb', line 8

def lang
  @lang
end

#resultObject

Returns the value of attribute result.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def result
  @result
end

#spaceObject

Returns the value of attribute space.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def space
  @space
end

Instance Method Details

#initObject



27
28
# File 'lib/ydocx/parser.rb', line 27

def init
end

#parseObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ydocx/parser.rb', line 29

def parse
  @doc.xpath('//w:document//w:body').children.map do |node|
    case node.node_name
    when 'text'
      @result << parse_paragraph(node)
    when 'tbl'
      @result << parse_table(node)
    when 'p'
      @result << parse_paragraph(node)
    else
      # skip
    end
  end
  @result
end