rowx 0.7.1 → 0.8.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/rowx.rb +41 -34
- data.tar.gz.sig +0 -0
- metadata +29 -28
- metadata.gz.sig +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d5b5fb10f2dfdaa035102203287878692974d8e49d7eb58b3e2ca23ef3c48771
         | 
| 4 | 
            +
              data.tar.gz: b01ecf96d3d126ac886af1bf9f66ec41244654740039ed8060aaa59c43f989bf
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e1dd96cc15cf5efb1c43cb15f976f553fa6f1f5bd28fcc3e17d215c805be54a629abe99632735158f05521071fa12aeb1c5dfb49c095dbc4c38ad6c78c1990db
         | 
| 7 | 
            +
              data.tar.gz: a28b1a65c3188502e5ee8395aabcc18de2f342d3558ff126a5ac2d2814b9b089e0f6498da914ee1989147d392cc4f65c39ec57df06fd865fba33ae25329e2c94
         | 
    
        checksums.yaml.gz.sig
    CHANGED
    
    | Binary file | 
    
        data/lib/rowx.rb
    CHANGED
    
    | @@ -8,15 +8,15 @@ require 'line-tree' | |
| 8 8 | 
             
            class RowXException < Exception
         | 
| 9 9 | 
             
            end
         | 
| 10 10 |  | 
| 11 | 
            -
            # for an example of ArrayCollate | 
| 11 | 
            +
            # for an example of ArrayCollate
         | 
| 12 12 | 
             
            # see http://www.jamesrobertson.eu/snippets/2014/jun/08/collating-items-in-an-array.html
         | 
| 13 13 |  | 
| 14 14 | 
             
            module ArrayCollate
         | 
| 15 15 | 
             
              refine Array do
         | 
| 16 16 | 
             
                def collate(pattern=nil)
         | 
| 17 17 | 
             
                  a = self.inject([[]]) do |r,x|
         | 
| 18 | 
            -
                    if block_given? then | 
| 19 | 
            -
                      yield(x) ? r << [x] : r[-1] << x | 
| 18 | 
            +
                    if block_given? then
         | 
| 19 | 
            +
                      yield(x) ? r << [x] : r[-1] << x
         | 
| 20 20 | 
             
                    else
         | 
| 21 21 | 
             
                      x =~ pattern ? r << [x] : r[-1] << x
         | 
| 22 22 | 
             
                    end # block
         | 
| @@ -24,24 +24,25 @@ module ArrayCollate | |
| 24 24 | 
             
                  end
         | 
| 25 25 | 
             
                  a.shift if a.first.empty?
         | 
| 26 26 | 
             
                  a
         | 
| 27 | 
            -
                end | 
| 27 | 
            +
                end
         | 
| 28 28 | 
             
              end
         | 
| 29 29 | 
             
            end
         | 
| 30 30 |  | 
| 31 31 | 
             
            class RowX
         | 
| 32 | 
            -
             | 
| 32 | 
            +
             | 
| 33 33 | 
             
              using ArrayCollate
         | 
| 34 | 
            -
              using ColouredText | 
| 34 | 
            +
              using ColouredText
         | 
| 35 35 |  | 
| 36 36 | 
             
              attr_reader :to_a, :to_xml, :to_lines
         | 
| 37 37 |  | 
| 38 | 
            -
              def initialize(txt, level: nil, ignore_blank_lines: false, | 
| 39 | 
            -
                             abort_1_row: false, debug: false, name: 'item' | 
| 40 | 
            -
             | 
| 38 | 
            +
              def initialize(txt, level: nil, ignore_blank_lines: false,
         | 
| 39 | 
            +
                             abort_1_row: false, debug: false, name: 'item',
         | 
| 40 | 
            +
                             allow_lonely_keyfield: false)
         | 
| 41 | 
            +
             | 
| 41 42 | 
             
                @name, @debug = name, debug
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                # auto indent any multiline values | 
| 44 | 
            -
             | 
| 43 | 
            +
             | 
| 44 | 
            +
                # auto indent any multiline values
         | 
| 45 | 
            +
             | 
| 45 46 | 
             
                indent = ''
         | 
| 46 47 |  | 
| 47 48 | 
             
                lines = txt.gsub(/^-+$/m,'').lines.map do |line|
         | 
| @@ -54,29 +55,34 @@ class RowX | |
| 54 55 | 
             
                  end
         | 
| 55 56 |  | 
| 56 57 | 
             
                end
         | 
| 57 | 
            -
             | 
| 58 | 
            +
             | 
| 58 59 | 
             
                puts 'lines: ' + lines.inspect if @debug
         | 
| 59 60 |  | 
| 60 | 
            -
                a = LineTree.new(lines.join, level: level, | 
| 61 | 
            +
                a = LineTree.new(lines.join, level: level,
         | 
| 61 62 | 
             
                                 ignore_blank_lines: ignore_blank_lines, debug: debug).to_a
         | 
| 62 63 | 
             
                puts ('a: ' + a.inspect).debug if @debug
         | 
| 63 64 |  | 
| 64 65 | 
             
                keyfield = a[0][0][/\w+:/]; i = 0
         | 
| 66 | 
            +
                puts ('keyfield: ' + keyfield.inspect).debug if @debug
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                if not allow_lonely_keyfield then
         | 
| 65 69 |  | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 70 | 
            +
                  # find the keyfield. if there's only 1 keyfield in all of the rows it's
         | 
| 71 | 
            +
                  # not a keyfield. Keep searching until all rows have been searched
         | 
| 72 | 
            +
                  while a.select {|x| x[0][/^#{keyfield}/]}.length <= 1 and \
         | 
| 73 | 
            +
                                                                    i < a.length and a[i+1]
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                    i += 1
         | 
| 76 | 
            +
                    keyfield = a[i][0][/\w+/]
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  end
         | 
| 73 79 |  | 
| 74 80 | 
             
                end
         | 
| 75 81 |  | 
| 76 82 | 
             
                keyfield = a[0][0][/\w+/] if i == a.length - 1
         | 
| 77 83 |  | 
| 78 84 | 
             
                if a.flatten(1).grep(/^#{keyfield}/).length == 1 then # only 1 record
         | 
| 79 | 
            -
                  i = 0 | 
| 85 | 
            +
                  i = 0
         | 
| 80 86 | 
             
                  raise RowXException, 'Expected more than 1 row' if abort_1_row
         | 
| 81 87 | 
             
                end
         | 
| 82 88 |  | 
| @@ -84,42 +90,43 @@ class RowX | |
| 84 90 |  | 
| 85 91 | 
             
                summary = scan_a a.slice!(0,i)
         | 
| 86 92 | 
             
                summary[0] = 'summary'
         | 
| 87 | 
            -
             | 
| 93 | 
            +
             | 
| 88 94 | 
             
                @rexle_a = scan_records(records, level)
         | 
| 89 95 | 
             
                @to_a = ['root', {}] + [summary] + @rexle_a
         | 
| 90 96 | 
             
                @to_xml = Rexle.new(@to_a).xml pretty: true
         | 
| 91 97 |  | 
| 92 98 | 
             
              end
         | 
| 93 | 
            -
             | 
| 99 | 
            +
             | 
| 94 100 | 
             
              def to_lines(delimiter: ' # ')
         | 
| 95 101 | 
             
                @rexle_a.map {|x| x[3..-1].map {|y| y[2]}.join(delimiter)}.join("\n").lines
         | 
| 96 102 | 
             
              end
         | 
| 97 103 |  | 
| 98 104 | 
             
              private
         | 
| 99 | 
            -
             | 
| 105 | 
            +
             | 
| 100 106 |  | 
| 101 107 | 
             
              def scan_a(row)
         | 
| 102 108 |  | 
| 103 109 | 
             
                a = row.map do |field|
         | 
| 104 110 |  | 
| 111 | 
            +
                  puts 'field: ' + field.inspect if @debug
         | 
| 105 112 | 
             
                  s = field.is_a?(Array) ? field[0] : field
         | 
| 106 113 |  | 
| 107 114 | 
             
                  return if s.empty?
         | 
| 115 | 
            +
                  puts 's: ' + s.inspect if @debug
         | 
| 116 | 
            +
                  found = s.match(/^(\w+)(?:\:$|\:\s*)(.*)/m)
         | 
| 108 117 |  | 
| 109 | 
            -
                   | 
| 110 | 
            -
             | 
| 111 | 
            -
                  value, name = found ? found.captures.reverse : s      
         | 
| 118 | 
            +
                  value, name = found ? found.captures.reverse : s
         | 
| 112 119 | 
             
                  name ||= 'description'
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                  children = scan_a(field[1..-1]) if field[-1] .is_a?(Array) | 
| 115 | 
            -
                  value = value.to_s.strip.gsub('<','<').gsub('>','>') | 
| 120 | 
            +
             | 
| 121 | 
            +
                  children = scan_a(field[1..-1]) if field[-1] .is_a?(Array)
         | 
| 122 | 
            +
                  value = value.to_s.strip.gsub('<','<').gsub('>','>')
         | 
| 116 123 |  | 
| 117 124 | 
             
                  # it's a line which has been commented out?
         | 
| 118 125 | 
             
                  if name[0] == '#' then
         | 
| 119 126 | 
             
                    value = name[1..-1] + ': ' + value
         | 
| 120 | 
            -
                    name = '!-' | 
| 127 | 
            +
                    name = '!-'
         | 
| 121 128 | 
             
                  end
         | 
| 122 | 
            -
             | 
| 129 | 
            +
             | 
| 123 130 | 
             
                  result = [name, {}, value]
         | 
| 124 131 | 
             
                  result << children if children
         | 
| 125 132 | 
             
                  result
         | 
| @@ -129,7 +136,7 @@ class RowX | |
| 129 136 | 
             
              end
         | 
| 130 137 |  | 
| 131 138 | 
             
              def scan_records(rows, level)
         | 
| 132 | 
            -
             | 
| 139 | 
            +
             | 
| 133 140 | 
             
                rows.map {|x| scan_a x }
         | 
| 134 141 |  | 
| 135 142 | 
             
              end
         | 
    
        data.tar.gz.sig
    CHANGED
    
    | Binary file | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rowx
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.8.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - James Robertson
         | 
| @@ -11,31 +11,31 @@ cert_chain: | |
| 11 11 | 
             
            - |
         | 
| 12 12 | 
             
              -----BEGIN CERTIFICATE-----
         | 
| 13 13 | 
             
              MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
         | 
| 14 | 
            -
               | 
| 15 | 
            -
               | 
| 16 | 
            -
               | 
| 17 | 
            -
               | 
| 18 | 
            -
               | 
| 19 | 
            -
               | 
| 20 | 
            -
               | 
| 21 | 
            -
               | 
| 22 | 
            -
               | 
| 23 | 
            -
               | 
| 24 | 
            -
               | 
| 25 | 
            -
               | 
| 26 | 
            -
               | 
| 14 | 
            +
              YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjAxMjA1NTM4WhcN
         | 
| 15 | 
            +
              MjMwMjAxMjA1NTM4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
         | 
| 16 | 
            +
              cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDtNLN7
         | 
| 17 | 
            +
              pZb3HdPluo1jqeNsq8eaVRqeRoLQLWjFVrVGq1h+jZlcyPs7SzcUw5dOtYq2cQkH
         | 
| 18 | 
            +
              NbzuRkobm+ls5nlN2kKT8l0tLcR/fDbp3+Eb72DdV1KlXlI3lYGPtcXAv2UUTi4D
         | 
| 19 | 
            +
              X0pEwM1Wg7pvQle8TbthXpvWRSUJ1sZz2369licKS+SV9PX2+7HctV2gny+D+XRi
         | 
| 20 | 
            +
              0NflrTRqYKSkF45GzGnJq/Csm8mB0JY9S11Df/PzR+FvRiZCgSi1Whxzuq/dJfBg
         | 
| 21 | 
            +
              EZxsgy2DW2uPBpbDctVZrYxc3pVcXOWiXLxhLBdF3+2Z/oyWeV2B3LBrZIerwQYL
         | 
| 22 | 
            +
              wUZQGtj6DRUztX9PcAnwQVtF4MtXcB24BXQsdg9psMMyTfMV1nXXom8/WVGgFxdv
         | 
| 23 | 
            +
              8PJaOhvH9mG26f42mG79tcxGkKF7S1QFM96btx74Rok5JEsADMMqXW3Dm+ea96KD
         | 
| 24 | 
            +
              OJrHTmW6QakT4NMA/QQIBWNM9dChqBBv4PULphtgNdIHk+1KkmSplDqRUcsCAwEA
         | 
| 25 | 
            +
              AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUx/xcU0TK
         | 
| 26 | 
            +
              9bnACymtt/UEgTnEU8EwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
         | 
| 27 27 | 
             
              c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
         | 
| 28 | 
            -
               | 
| 29 | 
            -
               | 
| 30 | 
            -
               | 
| 31 | 
            -
               | 
| 32 | 
            -
               | 
| 33 | 
            -
               | 
| 34 | 
            -
               | 
| 35 | 
            -
               | 
| 36 | 
            -
               | 
| 28 | 
            +
              BgkqhkiG9w0BAQsFAAOCAYEAK1wuYV0sR94i1wOFUaqfyPSvUf11WKHyhUTHtfQY
         | 
| 29 | 
            +
              9FXtSJLAFFYo0m30ChHoJE8XMkNtS1Vc4dBm/z8njoAR0FSuE77Br4N5m9VZqiE1
         | 
| 30 | 
            +
              8M0Mhd19q3vhnRs/5Jw1sR1Ct+F1FHPTZAF1SJfPepUnlbnR+sClQENs7R7GXEuu
         | 
| 31 | 
            +
              KEdbSo9fKidw/ZSPpqb7RZ2ptfEAVsJkuF0Lf/bhpuLvxwdNvC2YpbQwLiEeOAbL
         | 
| 32 | 
            +
              pKRxInKqWnabRZHVg59Oxvw6WRBzfS4lF793ut6w05JX7f+9X/4g5/NwKlHh7vbx
         | 
| 33 | 
            +
              wusUvr5gPBCocxOnqPbKdOLOWGuHoVe6pKaUFFxVBj2R1dC/ErqNMdj0AxQoSgTi
         | 
| 34 | 
            +
              aDvs3bDHPgW1IHO4PWdeXr8KBfTIr1n0qrZ1IF4rNeTiTf4Pqo7x8VrpvNN3sG6/
         | 
| 35 | 
            +
              kfXR2KNu3kHN0g9PsBdrL79ctMBurBHn/ATYdhoOG4ebjY2ubJz5nR9sOONJUroJ
         | 
| 36 | 
            +
              AB0aDh+E6dzxvdb+vmfSBHJb
         | 
| 37 37 | 
             
              -----END CERTIFICATE-----
         | 
| 38 | 
            -
            date:  | 
| 38 | 
            +
            date: 2022-02-01 00:00:00.000000000 Z
         | 
| 39 39 | 
             
            dependencies:
         | 
| 40 40 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 41 41 | 
             
              name: line-tree
         | 
| @@ -46,7 +46,7 @@ dependencies: | |
| 46 46 | 
             
                    version: '0.9'
         | 
| 47 47 | 
             
                - - ">="
         | 
| 48 48 | 
             
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            -
                    version: 0.9. | 
| 49 | 
            +
                    version: 0.9.3
         | 
| 50 50 | 
             
              type: :runtime
         | 
| 51 51 | 
             
              prerelease: false
         | 
| 52 52 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -56,9 +56,9 @@ dependencies: | |
| 56 56 | 
             
                    version: '0.9'
         | 
| 57 57 | 
             
                - - ">="
         | 
| 58 58 | 
             
                  - !ruby/object:Gem::Version
         | 
| 59 | 
            -
                    version: 0.9. | 
| 59 | 
            +
                    version: 0.9.3
         | 
| 60 60 | 
             
            description: Generates XML from rows of labelled text, nested text,  and plain text
         | 
| 61 | 
            -
            email:  | 
| 61 | 
            +
            email: digital.robertson@gmail.com
         | 
| 62 62 | 
             
            executables: []
         | 
| 63 63 | 
             
            extensions: []
         | 
| 64 64 | 
             
            extra_rdoc_files: []
         | 
| @@ -83,7 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 83 83 | 
             
                - !ruby/object:Gem::Version
         | 
| 84 84 | 
             
                  version: '0'
         | 
| 85 85 | 
             
            requirements: []
         | 
| 86 | 
            -
             | 
| 86 | 
            +
            rubyforge_project: 
         | 
| 87 | 
            +
            rubygems_version: 2.7.10
         | 
| 87 88 | 
             
            signing_key: 
         | 
| 88 89 | 
             
            specification_version: 4
         | 
| 89 90 | 
             
            summary: rowx
         | 
    
        metadata.gz.sig
    CHANGED
    
    | Binary file |