jsoner 0.0.2 → 0.0.3
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 +8 -8
 - data/CHANGELOG.md +4 -0
 - data/lib/jsoner.rb +17 -1
 - data/lib/jsoner/table_factory.rb +12 -0
 - data/lib/jsoner/version.rb +1 -1
 - data/spec/fixtures/table.html +26 -0
 - data/spec/fixtures/table_extend.html +20 -0
 - data/spec/jsoner_spec.rb +8 -0
 - metadata +5 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,15 +1,15 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            !binary "U0hBMQ==":
         
     | 
| 
       3 
3 
     | 
    
         
             
              metadata.gz: !binary |-
         
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
                NjZiMGZjNWIxMzhjMmFkMzRlYTJiYTIyYjdiMjY5ZTc5YzM2MDI4MA==
         
     | 
| 
       5 
5 
     | 
    
         
             
              data.tar.gz: !binary |-
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
                YWMyZjYzNzNkZGYzNDA3NjkwMDlkNTMzNmJkMTYwMmU1NGNkNWQ0OQ==
         
     | 
| 
       7 
7 
     | 
    
         
             
            !binary "U0hBNTEy":
         
     | 
| 
       8 
8 
     | 
    
         
             
              metadata.gz: !binary |-
         
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 9 
     | 
    
         
            +
                ZTMxNGU2NjU2NzA4YzRiN2RlYTcyOWIxMGQyMDlhYzNkY2I4YzJjYmEwMzhj
         
     | 
| 
      
 10 
     | 
    
         
            +
                ZWZhM2FhODg1MTc1NWY4OGEyZjg5NTgyMGVlMmM2YzUxZjdhMjE5YTA3YmU0
         
     | 
| 
      
 11 
     | 
    
         
            +
                NGM4NzQ3ZTU4YTljNzYzZmY0MGFkMWZmNDk2ZTYxNzg1NmRkMjE=
         
     | 
| 
       12 
12 
     | 
    
         
             
              data.tar.gz: !binary |-
         
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 13 
     | 
    
         
            +
                NWMxNjkyMjQ1Y2YwZTkwODhhYTgyNmQwM2UxMzMxM2Y4Y2EzYTIyNjgxNGM3
         
     | 
| 
      
 14 
     | 
    
         
            +
                MDIzZDdkODliNDY4ZjQwYzE0NmJiMzQ4YTUyMWFkYzAzOTM3ZjYzNDI2NDUw
         
     | 
| 
      
 15 
     | 
    
         
            +
                YTQwM2Y0YjQ0MTAzNTE3YTFiZTgyNDZjZDY1NTJhMGY2MjQyZTg=
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/jsoner.rb
    CHANGED
    
    | 
         @@ -5,10 +5,26 @@ require "jsoner/table_factory" 
     | 
|
| 
       5 
5 
     | 
    
         
             
            require 'nokogiri'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            module Jsoner
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              class NotFullTable < StandardError
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       8 
12 
     | 
    
         
             
              class << self
         
     | 
| 
       9 
13 
     | 
    
         | 
| 
       10 
14 
     | 
    
         
             
                def parse(html)
         
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
      
 15 
     | 
    
         
            +
                  html = filter(html)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  if factory = Jsoner::TableFactory.check(Nokogiri::HTML.parse(html))
         
     | 
| 
      
 17 
     | 
    
         
            +
                    Jsoner::Table.new(factory).to_json
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
               
         
     | 
| 
      
 21 
     | 
    
         
            +
                def filter html
         
     | 
| 
      
 22 
     | 
    
         
            +
                  if File.file? html
         
     | 
| 
      
 23 
     | 
    
         
            +
                    File.open(html) { |file| file.read } 
         
     | 
| 
      
 24 
     | 
    
         
            +
                  else
         
     | 
| 
      
 25 
     | 
    
         
            +
            	html
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
       12 
27 
     | 
    
         
             
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
                
         
     | 
| 
       13 
29 
     | 
    
         
             
              end
         
     | 
| 
       14 
30 
     | 
    
         
             
            end
         
     | 
    
        data/lib/jsoner/table_factory.rb
    CHANGED
    
    | 
         @@ -29,6 +29,18 @@ module Jsoner 
     | 
|
| 
       29 
29 
     | 
    
         
             
                  end
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
                # 
         
     | 
| 
      
 33 
     | 
    
         
            +
                # check whether table is full
         
     | 
| 
      
 34 
     | 
    
         
            +
                # a full table should include +th+, +td+, +tr+ elements
         
     | 
| 
      
 35 
     | 
    
         
            +
                def self.check doc
         
     | 
| 
      
 36 
     | 
    
         
            +
                  table = doc.search('table').first
         
     | 
| 
      
 37 
     | 
    
         
            +
                  unless table.search('tr').empty? || table.search('td').empty? || table.search('th').empty?
         
     | 
| 
      
 38 
     | 
    
         
            +
                    TableFactory.new doc
         
     | 
| 
      
 39 
     | 
    
         
            +
                  else
         
     | 
| 
      
 40 
     | 
    
         
            +
            	raise Jsoner::NotFullTable
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       32 
44 
     | 
    
         
             
                private
         
     | 
| 
       33 
45 
     | 
    
         | 
| 
       34 
46 
     | 
    
         
             
                  #
         
     | 
    
        data/lib/jsoner/version.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <table id='example-table'>
         
     | 
| 
      
 2 
     | 
    
         
            +
              <thead>
         
     | 
| 
      
 3 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 4 
     | 
    
         
            +
                  <th>First Name</th>
         
     | 
| 
      
 5 
     | 
    
         
            +
                  <th>Last Name</th>
         
     | 
| 
      
 6 
     | 
    
         
            +
                  <th data-override="Score">Points</th></tr>
         
     | 
| 
      
 7 
     | 
    
         
            +
              </thead>
         
     | 
| 
      
 8 
     | 
    
         
            +
              <tbody>
         
     | 
| 
      
 9 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 10 
     | 
    
         
            +
                  <td>Jill</td>
         
     | 
| 
      
 11 
     | 
    
         
            +
                  <td>Smith</td>
         
     | 
| 
      
 12 
     | 
    
         
            +
                  <td data-override="disqualified">50</td></tr>
         
     | 
| 
      
 13 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 14 
     | 
    
         
            +
                  <td>Eve</td>
         
     | 
| 
      
 15 
     | 
    
         
            +
                  <td>Jackson</td>
         
     | 
| 
      
 16 
     | 
    
         
            +
                  <td>94</td></tr>
         
     | 
| 
      
 17 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 18 
     | 
    
         
            +
                  <td>John</td>
         
     | 
| 
      
 19 
     | 
    
         
            +
                  <td>Doe</td>
         
     | 
| 
      
 20 
     | 
    
         
            +
                  <td>80</td></tr>
         
     | 
| 
      
 21 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 22 
     | 
    
         
            +
                  <td>Adam</td>
         
     | 
| 
      
 23 
     | 
    
         
            +
                  <td>Johnson</td>
         
     | 
| 
      
 24 
     | 
    
         
            +
                  <td>67</td></tr>
         
     | 
| 
      
 25 
     | 
    
         
            +
              </tbody>
         
     | 
| 
      
 26 
     | 
    
         
            +
            </table>
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <table id='example-table'>
         
     | 
| 
      
 2 
     | 
    
         
            +
              <tbody>
         
     | 
| 
      
 3 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 4 
     | 
    
         
            +
                  <td>Jill</td>
         
     | 
| 
      
 5 
     | 
    
         
            +
                  <td>Smith</td>
         
     | 
| 
      
 6 
     | 
    
         
            +
                  <td data-override="disqualified">50</td></tr>
         
     | 
| 
      
 7 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 8 
     | 
    
         
            +
                  <td>Eve</td>
         
     | 
| 
      
 9 
     | 
    
         
            +
                  <td>Jackson</td>
         
     | 
| 
      
 10 
     | 
    
         
            +
                  <td>94</td></tr>
         
     | 
| 
      
 11 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 12 
     | 
    
         
            +
                  <td>John</td>
         
     | 
| 
      
 13 
     | 
    
         
            +
                  <td>Doe</td>
         
     | 
| 
      
 14 
     | 
    
         
            +
                  <td>80</td></tr>
         
     | 
| 
      
 15 
     | 
    
         
            +
                <tr>
         
     | 
| 
      
 16 
     | 
    
         
            +
                  <td>Adam</td>
         
     | 
| 
      
 17 
     | 
    
         
            +
                  <td>Johnson</td>
         
     | 
| 
      
 18 
     | 
    
         
            +
                  <td>67</td></tr>
         
     | 
| 
      
 19 
     | 
    
         
            +
              </tbody>
         
     | 
| 
      
 20 
     | 
    
         
            +
            </table>
         
     | 
    
        data/spec/jsoner_spec.rb
    CHANGED
    
    | 
         @@ -6,4 +6,12 @@ describe Jsoner do 
     | 
|
| 
       6 
6 
     | 
    
         
             
              it "should match data from json of fixtures" do
         
     | 
| 
       7 
7 
     | 
    
         
             
                Jsoner.parse(table_str).should == json
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              it "should parse file including table" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                Jsoner.parse("#{File.dirname(__FILE__)}/fixtures/table.html").should == json
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              it "should raise error when having no full table in HTML file" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                expect{ Jsoner.parse("#{File.dirname(__FILE__)}/fixtures/table_extend.html")}.to raise_error Jsoner::NotFullTable
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
       9 
17 
     | 
    
         
             
            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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - simlegate
         
     | 
| 
         @@ -86,7 +86,9 @@ files: 
     | 
|
| 
       86 
86 
     | 
    
         
             
            - lib/jsoner/table_factory.rb
         
     | 
| 
       87 
87 
     | 
    
         
             
            - lib/jsoner/version.rb
         
     | 
| 
       88 
88 
     | 
    
         
             
            - spec/fixtures/json.rb
         
     | 
| 
      
 89 
     | 
    
         
            +
            - spec/fixtures/table.html
         
     | 
| 
       89 
90 
     | 
    
         
             
            - spec/fixtures/table.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - spec/fixtures/table_extend.html
         
     | 
| 
       90 
92 
     | 
    
         
             
            - spec/fixtures/table_extend.rb
         
     | 
| 
       91 
93 
     | 
    
         
             
            - spec/jsoner/table_factory_spec.rb
         
     | 
| 
       92 
94 
     | 
    
         
             
            - spec/jsoner/table_spec.rb
         
     | 
| 
         @@ -117,7 +119,9 @@ specification_version: 4 
     | 
|
| 
       117 
119 
     | 
    
         
             
            summary: Serialize HTML tables into JSON in Ruby
         
     | 
| 
       118 
120 
     | 
    
         
             
            test_files:
         
     | 
| 
       119 
121 
     | 
    
         
             
            - spec/fixtures/json.rb
         
     | 
| 
      
 122 
     | 
    
         
            +
            - spec/fixtures/table.html
         
     | 
| 
       120 
123 
     | 
    
         
             
            - spec/fixtures/table.rb
         
     | 
| 
      
 124 
     | 
    
         
            +
            - spec/fixtures/table_extend.html
         
     | 
| 
       121 
125 
     | 
    
         
             
            - spec/fixtures/table_extend.rb
         
     | 
| 
       122 
126 
     | 
    
         
             
            - spec/jsoner/table_factory_spec.rb
         
     | 
| 
       123 
127 
     | 
    
         
             
            - spec/jsoner/table_spec.rb
         
     |