class DocTemplate::Tags::VocabularyTag

Constants

TAG_NAME
TEMPLATE

Public Instance Methods

parse_table(table) click to toggle source
# File lib/doc_template/tags/vocabulary_tag.rb, line 9
def parse_table(table)
  params = { sections: fetch_content(table) }
  parsed_content = parse_template params, TEMPLATE
  @content = parse_nested parsed_content, @opts
  replace_tag table
end

Private Instance Methods

fetch_content(node) click to toggle source
# File lib/doc_template/tags/vocabulary_tag.rb, line 18
def fetch_content(node)
  [].tap do |result|
    # omit the first row
    cur_section = nil
    node.xpath('.//tr[position() > 1]').each do |tr|
      if (td_header = tr.at_xpath "./td[@colspan = '2']")
        result << cur_section if cur_section.present?
        cur_section = { title: td_header.text }
      elsif cur_section.present?
        cur_section[:words] ||= []
        cur_section[:words] << { name: tr.at_xpath('./td[1]').text, definition: tr.at_xpath('./td[2]').text }
      end
    end
    result << cur_section
  end
end