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

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

Constant Summary collapse

INSTANCE =
new

Instance Method Summary collapse

Methods inherited from Base

#extract_leading_trailing_whitespace, #extract_text_from_content, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#extract_title(node) ⇒ Object



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

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

  title.text.strip
end

#frame(node) ⇒ Object



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

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

#rules(node) ⇒ Object



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

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



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

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