Class: Obp::Access::TableMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/obp/access/table_mapper.rb

Overview

Maps the table-carrying nodes of an OBP preview HTML fragment — div.sts-table-wrap and div.sts-array, in document order — to a generic table model built from plain hashes, arrays and strings, ready for YAML serialization. This is an additive read of the same HTML source the Converter renders to STS XML; TableTermExtractor consumes this model.

Constant Summary collapse

WRAP_SELECTOR =

Both wrapper kinds carry a single

.

"div.sts-table-wrap, div.sts-array"
SECTION_ID_PATTERN =

Section ids look like "toc_iso_std_iso_80000-12_ed-2_v2_en_sec_3"; the clause key is whatever follows "sec" ("3", "1.1", "index").

/_sec_(.+)\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:) ⇒ TableMapper

Returns a new instance of TableMapper.



24
25
26
# File 'lib/obp/access/table_mapper.rb', line 24

def initialize(source:)
  @source = source
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



22
23
24
# File 'lib/obp/access/table_mapper.rb', line 22

def source
  @source
end

Instance Method Details

#tablesObject



28
29
30
# File 'lib/obp/access/table_mapper.rb', line 28

def tables
  @tables ||= wraps.map { |node| map_table(node) }
end

#to_yamlObject



32
33
34
# File 'lib/obp/access/table_mapper.rb', line 32

def to_yaml
  tables.to_yaml
end