pxrowx 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bf699435736bd1721ea6f186fbc0a7a33e12b02
4
+ data.tar.gz: 02b4b540adb0df8ecc0178dc060dbd70992a946f
5
+ SHA512:
6
+ metadata.gz: 14ae3923d8f6f3888a4d991de7ebd2e16b9d41f6fd3434701213f6dd43aa3ac6f71e4c6703d651eeb6eb027b3fc428c246282161873d2a35120387acd5058fe1
7
+ data.tar.gz: 933ff87ca2262c4cd6eda4e910bbe8bd68dc39dcfa04c4dca5e567e64ef659a6af54c93bf4682344cc26f86bef718fefd3f686210b6b9bcae9564a8c49487c19
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/pxrowx.rb ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: pxrowx.rb
4
+
5
+ require 'line-tree'
6
+
7
+
8
+ class PxRowX
9
+
10
+ def initialize(txt)
11
+
12
+ lt = LineTree.new(txt)
13
+ a = lt.to_a
14
+
15
+ labels = []
16
+
17
+ i = 0
18
+ label = a[i][0][/^\w+/]
19
+
20
+ while (not labels.include?(label)) and i < a.length do
21
+
22
+ labels << label
23
+ i+=1
24
+ label = a[i][0][/^\w+/]
25
+
26
+ end
27
+
28
+ r = scan_tree labels.length, a
29
+
30
+ rows = make_rows r
31
+
32
+ ['items', {}, nil].reverse.each {|x| rows.unshift x}
33
+ @doc = Rexle.new(rows)
34
+
35
+ end
36
+
37
+ def to_xml(options={})
38
+ @doc.xml options
39
+ end
40
+
41
+ private
42
+
43
+ def scan_tree(n, a)
44
+
45
+ items = []
46
+ item = a.first
47
+
48
+ while a.any? do
49
+
50
+ if item.length < 2 then
51
+
52
+ items << n.times.flat_map do
53
+
54
+ r = []
55
+ line = a.shift
56
+
57
+ r << line.shift
58
+ r << scan_tree(n, line) unless line.empty?
59
+ r
60
+
61
+ end
62
+
63
+ else
64
+ scan n, a
65
+ end
66
+
67
+ end
68
+
69
+ return items
70
+
71
+ end
72
+
73
+ def make_rows(a)
74
+
75
+ a.inject([]) do |r, x|
76
+
77
+ if x.is_a? String then
78
+
79
+ r = ['item',{},nil, ['summary',{}, nil ]] if r.empty?
80
+ field, value = x.split(/:\s*/,2)
81
+ r.last << [field, {}, value]
82
+
83
+ elsif x.is_a? Array
84
+
85
+ if x.length > 1 then
86
+ r << make_rows(x)
87
+ else
88
+ r << ['records', {}, nil, make_rows(x.first)]
89
+ end
90
+
91
+ end
92
+
93
+ r
94
+ end
95
+ end
96
+ end
97
+
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pxrowx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE2MTEyMDE2NTAyNFoXDTE3MTEyMDE2NTAyNFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAMRQMXgxGLLbmBM4a9C00d4BDMPLVuJ61KOpD1stjMxvZ9lpKxPaQ/Z3Z1Pz
19
+ xhozm4rf3rQ5WZD3X4m+fBejYN5SHyUkty2g1AB0zmAV4H/z02cvdfhlIBZcAmFX
20
+ 0vyBC/s0vWCxtE2XMGYxyTcHRoN70e5Dnq2Sj3ROBAGbaiAo9mAfwdQM/L0yiMyh
21
+ AqbxtuYnMMJYbF+fzRFmLeXzidYOIZYHsdvA4F/G6EHt3rvOfzo0U+YPhTnAvdpj
22
+ C8gYsodOxR1UDaJASy2MNgadwFQBq2FPGyNVeGC2sALGlEinN4Qy7QwnFgAbg8lS
23
+ 8HCBVvj0oGTTOHOzu2GMMWp8HSkCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUmSnUFBzboP8IUBeZQAzL+E1IeacwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAPU3Lktl4
27
+ 95IORB04O8xYTrUfMsKMLqM64xCaTSH5LCWEp6IKHrumvlsN6j5mrjq2luJlhjGQ
28
+ NuOQ8F1GFZ4Cy7tOAnPkAg9sG5pAMChVZmCEsE5AR2kGvHsORRdq3dQIL3MjZmUo
29
+ kqjSxZyZj9rmKpN+WhKkodnRWhFtD78VqplqE+z+YhH/XF5Hb6Be973BiTXQaAPp
30
+ nnxuJ1NClzMlURskTMimFa6GkrDsu3GhjMjKQKFEVgBRT8WDbByF6M35T/BGy00n
31
+ pkBwAqlR25JVgr8VTfX/ib2qW3boooPPz10VstLGg/f0QvT7Krw4FUMi5GlKkXD/
32
+ BdQSzvwx2Iy5kw==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-11-20 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: line-tree
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.5'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.6
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.5'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.5.6
56
+ description:
57
+ email: james@r0bertson.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/pxrowx.rb
63
+ homepage: https://github.com/jrobertson/pxrowx
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Creates a Polyrex document from a raw Polyrex RowX string.
87
+ test_files: []
metadata.gz.sig ADDED
Binary file