Class: Coradoc::Input::Html::Converters::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/html/input/converters/table.rb

Instance Method Summary collapse

Methods inherited from Base

#convert, #escape_text, #extract_leading_trailing_whitespace, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#extract_title(node) ⇒ Object



26
27
28
29
30
31
# File 'lib/coradoc/html/input/converters/table.rb', line 26

def extract_title(node)
  title = node.at('./caption')
  return nil if title.nil?

  title.text.strip
end

#frame(node) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/coradoc/html/input/converters/table.rb', line 33

def frame(node)
  case node['frame']
  when 'void'
    'none'
  when 'hsides'
    'topbot'
  when 'vsides'
    'sides'
  when 'box', 'border'
    'all'
  end
end

#rules(node) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/coradoc/html/input/converters/table.rb', line 46

def rules(node)
  case node['rules']
  when 'all'
    'all'
  when 'rows'
    'rows'
  when 'cols'
    'cols'
  when 'none'
    'none'
  end
end

#to_coradoc(node, state = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coradoc/html/input/converters/table.rb', line 8

def to_coradoc(node, state = {})
  id = node['id']
  title = extract_title(node)
  content = treat_children_coradoc(node, state)

  # Apply frame and grid attributes if available
  frame_attr = frame(node)
  grid_attr = rules(node)

  Coradoc::CoreModel::Table.new(
    title: title,
    rows: content,
    id: id,
    frame: frame_attr,
    grid: grid_attr
  )
end