table_parser 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +2 -2
- data/lib/table_parser.rb +1 -1
- data/lib/table_parser/table.rb +9 -2
- data/test/test_table_parser.rb +1 -1
- metadata +1 -1
data/README.txt
CHANGED
@@ -35,7 +35,7 @@ Note the first column contains duplicated item, because the first row contains "
|
|
35
35
|
html = "<html><body><table><tr><td>A</td><td>B</td></tr>\
|
36
36
|
<tr><td rowspan=\"2\">1</td><td>2</td></tr> \
|
37
37
|
<tr><td>3</td></tr></table></body></html>"
|
38
|
-
table = TableParser::Table.new(html, "/html/body/table", false)
|
38
|
+
table = TableParser::Table.new(html, "/html/body/table", {:dup_rows => false})
|
39
39
|
</pre>
|
40
40
|
|
41
41
|
Which result in following parsed table:
|
@@ -47,7 +47,7 @@ Table<TableColumn<name=A, children=[1],[1]>,TableColumn<name=B, chil
|
|
47
47
|
|
48
48
|
== DEVELOPERS:
|
49
49
|
|
50
|
-
* Francis Chong francis at ignition dot hk
|
50
|
+
* Francis Chong, francis at ignition dot hk
|
51
51
|
|
52
52
|
== LICENSE:
|
53
53
|
|
data/lib/table_parser.rb
CHANGED
data/lib/table_parser/table.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
module TableParser
|
2
2
|
class Table
|
3
3
|
attr_reader :nodes, :columns
|
4
|
-
def initialize(input, xpath_to_table="//table[0]",
|
4
|
+
def initialize(input, xpath_to_table="//table[0]", options={})
|
5
|
+
|
6
|
+
if options.has_key? :dup_rows
|
7
|
+
dup_rows = options[:dup_rows]
|
8
|
+
else
|
9
|
+
dup_rows = true
|
10
|
+
end
|
11
|
+
|
5
12
|
table = Parser.extract_table(input, xpath_to_table)
|
6
13
|
@columns = Parser.extract_column_headers(table)
|
7
|
-
@nodes = Parser.extract_nodes(table, @columns,
|
14
|
+
@nodes = Parser.extract_nodes(table, @columns, dup_rows)
|
8
15
|
end
|
9
16
|
|
10
17
|
def to_s
|
data/test/test_table_parser.rb
CHANGED
@@ -18,7 +18,7 @@ class TestTableParser < Test::Unit::TestCase
|
|
18
18
|
table = TableParser::Table.new "<html><body><table><tr><td>A</td><td>B</td></tr>\
|
19
19
|
<tr><td rowspan=\"2\">1</td><td>2</td></tr> \
|
20
20
|
<tr><td>3</td></tr></table></body></html>",
|
21
|
-
"/html/body/table", false
|
21
|
+
"/html/body/table", {:dup_rows => false}
|
22
22
|
|
23
23
|
puts table
|
24
24
|
assert_equal(2, table.columns.size, 'header_count should = 2 ')
|