Class: Concordion::Instrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/concordion/instrumenter.rb

Constant Summary collapse

@@TH_CSS_QUERY_REGEXP =
/tr:nth\(\d+\) > th:nth\((\d+)\)$/
@@TH_CSS_SINGLE_REGEXP =
/tr:nth\(\d+\) > th$/

Instance Method Summary collapse

Instance Method Details

#instrument_column(elem, attr, column_number, regex, root) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/concordion/instrumenter.rb', line 23

def instrument_column(elem, attr, column_number, regex, root)
  trimmed = elem.css_path.sub(regex, '')
  td_css_query = trimmed + "tr > td:nth(#{column_number})"

  value = elem.get_attribute(attr)
  root.search(td_css_query).set(attr, value)
end

#instrument_from_headers(elem, attr, root) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/concordion/instrumenter.rb', line 7

def instrument_from_headers(elem, attr, root)
  header = @@TH_CSS_QUERY_REGEXP.match(elem.css_path)
  if header
    instrument_column(elem, attr, header.captures, @@TH_CSS_QUERY_REGEXP, root)
    return true
  end

  single_header = @@TH_CSS_SINGLE_REGEXP.match(elem.css_path)
  if single_header
    instrument_column(elem, attr, 0, @@TH_CSS_SINGLE_REGEXP, root)
    return true
  end

  false
end