jsoner 0.0.1.rc1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTZkOTEzMGYxM2QzMzFkNzdjMjBmZjU2OGZmODdkYzc2YzAwZTBiOQ==
4
+ ZWU0NTgzMGIxYmIwMzU0ZmRiNGFiZjIwMTFiNjI2ODFhNmZlNjJiYw==
5
5
  data.tar.gz: !binary |-
6
- MWI5NWFiNTk2NTdkM2NmZjFlOGY1NzAzNWMwZDRiZjk1NTIzN2U0ZQ==
6
+ ZDczZTFiODkyM2RjZjIwMzIwZGY5YzEzN2ZiNDU4MzYyMGEyZmZlYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGY0NzFiMGQ5OWIxOGNiYTY4ZTBkNTg5OThiOTAzNGY3MjY3ZmJkYzRlZmJk
10
- NmQyNmFlNDc5ZWQwYjQ3ZjI5YzlmNDAzY2IzNGU5MTI3YTJjYmIwYjNkYjE4
11
- Mzk3ZTUyYzAwNjg1MmUxZTExNjBiYTE1NTRlNTVkNGIyOWQ3NjY=
9
+ YzY5ODk0ZDhkMDcwNDgwYzFmMTJiNmM3NmViY2I3NDExYWM2NTY1ZmQwMzE0
10
+ MjJhMmQxMjVjZjhmZTgzMDJmMDEwNDE0MzM3YWEyYmM5NzIzOTUxNjQ4MGRm
11
+ YmNjNzUzNTJmZWY3ODcyNmNiN2QyNTI1NWFjMjNiOGU2MzI1ZGQ=
12
12
  data.tar.gz: !binary |-
13
- MTc4MjE3NTFkYWNiODkwMTUxZGYyMDA1YzYxYzExMjRiMTBmNWY2NzkzNDkx
14
- NDkwMmZmNzcxMjViYTk1ZmFjMzViYzhlNmZlN2I5MjhmNWMwY2E4YWRiYWQ4
15
- ZmM1MTkyNzI3MDY0YTAyMzA4MjE4MTFkYjU5NjgzN2EzYjU2YWM=
13
+ ZDczYTliYzA2NTc0MjAwZDExMWIwOWEyYjdjNTA3M2FiZjUwODc1MTYxNmZi
14
+ MDJkNDIwM2I2Y2FjM2M3ZDBkYjMyYjkyNjFjZjU4NDQ1ZTZjNGNlYjY4YzVh
15
+ MTEzZjQwOTI2YTBiYWUwZDA1N2UzYzVmNDIyODhiNzYxZjBmMmU=
@@ -0,0 +1,3 @@
1
+ ## v0.0.2
2
+ * Filter other elements beyond table element
3
+ * Get first table element when having more than two in parsed HTML
@@ -11,7 +11,7 @@ module Jsoner
11
11
  class TableFactory
12
12
 
13
13
  def initialize doc
14
- @table_rows = doc.search('tr')
14
+ @table_rows = remove_housing(doc).search('tr')
15
15
  end
16
16
 
17
17
  def create
@@ -33,19 +33,24 @@ module Jsoner
33
33
 
34
34
  #
35
35
  # Remove other elements beside table and keep it clean
36
+ # Or keep one table when including more than two table elements in parsed HTML
36
37
  #
37
38
  # Example:
38
39
  # <body>
39
40
  # <table>
40
41
  # // other elements
41
42
  # </table>
43
+ # <table>
44
+ # // other elements
45
+ # </table>
42
46
  # </body>
43
47
  #
44
48
  # Output:
45
49
  # <table>
46
50
  # // other elements
47
51
  # </table>
48
- def remove_housing
52
+ def remove_housing doc
53
+ doc.search('table').first
49
54
  end
50
55
  end
51
56
  end
@@ -1,3 +1,3 @@
1
1
  module Jsoner
2
- VERSION = "0.0.1.rc1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,34 @@
1
+ def table_extend_str
2
+ <<-eohtml
3
+ <body>
4
+ <table id='example-table'>
5
+ <thead>
6
+ <tr>
7
+ <th>First Name</th>
8
+ <th>Last Name</th>
9
+ <th data-override="Score">Points</th></tr>
10
+ </thead>
11
+ <tbody>
12
+ <tr>
13
+ <td>Jill</td>
14
+ <td>Smith</td>
15
+ <td data-override="disqualified">50</td></tr>
16
+ <tr>
17
+ <td>Eve</td>
18
+ <td>Jackson</td>
19
+ <td>94</td></tr>
20
+ <tr>
21
+ <td>John</td>
22
+ <td>Doe</td>
23
+ <td>80</td></tr>
24
+ <tr>
25
+ <td>Adam</td>
26
+ <td>Johnson</td>
27
+ <td>67</td></tr>
28
+ </tbody>
29
+ </table>
30
+ <table>
31
+ </table>
32
+ </body>
33
+ eohtml
34
+ end
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../fixtures/table"
1
+ Dir["#{File.dirname(__FILE__)}/fixtures/*.rb"].each {|file| require file }
2
2
  require "#{File.dirname(__FILE__)}/../../lib/jsoner"
3
3
 
4
4
  describe 'build Hash below from doc parsed by Nokogiki' do
@@ -51,4 +51,28 @@ describe 'build Hash below from doc parsed by Nokogiki' do
51
51
 
52
52
  # TODO testing when having no header in table
53
53
  end
54
+
55
+ context "filter HTML" do
56
+
57
+ before :each do
58
+ @ext_obj = Nokogiri::HTML.parse(table_extend_str)
59
+ @ext_factory = Jsoner::TableFactory.new(@ext_obj)
60
+ end
61
+
62
+ it "@ext_obj should have two tables" do
63
+ @ext_obj.search('table').count.should == 2
64
+ end
65
+
66
+ it "second table have no descendant nodes" do
67
+ @ext_obj.search('table').last.search('descendant').should be_empty
68
+ end
69
+
70
+ it "first table should have _th_ elements" do
71
+ @ext_obj.search('table').first.search('th').count.should == 3
72
+ end
73
+
74
+ it "should get first table after search table default" do
75
+ @ext_factory.instance_variable_get(:@table_rows).search('tr').count.should ==5
76
+ end
77
+ end
54
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsoner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.rc1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - simlegate
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
77
  - .travis.yml
78
+ - CHANGELOG.md
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md
@@ -86,6 +87,7 @@ files:
86
87
  - lib/jsoner/version.rb
87
88
  - spec/fixtures/json.rb
88
89
  - spec/fixtures/table.rb
90
+ - spec/fixtures/table_extend.rb
89
91
  - spec/jsoner/table_factory_spec.rb
90
92
  - spec/jsoner/table_spec.rb
91
93
  - spec/jsoner_spec.rb
@@ -104,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
106
  version: '0'
105
107
  required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  requirements:
107
- - - ! '>'
109
+ - - ! '>='
108
110
  - !ruby/object:Gem::Version
109
- version: 1.3.1
111
+ version: '0'
110
112
  requirements: []
111
113
  rubyforge_project:
112
114
  rubygems_version: 2.0.6
@@ -116,6 +118,7 @@ summary: Serialize HTML tables into JSON in Ruby
116
118
  test_files:
117
119
  - spec/fixtures/json.rb
118
120
  - spec/fixtures/table.rb
121
+ - spec/fixtures/table_extend.rb
119
122
  - spec/jsoner/table_factory_spec.rb
120
123
  - spec/jsoner/table_spec.rb
121
124
  - spec/jsoner_spec.rb