rowx 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/rowx.rb +32 -32
  4. data.tar.gz.sig +0 -0
  5. metadata +29 -28
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 117e67e111222ae3340f55869da655ee10e6e94f538cef074d70a977f58f522d
4
- data.tar.gz: c89eb4d40e0df4f8aea3dbb7214979365f23fd9dfb146e8b961f391863d36c17
3
+ metadata.gz: d5b5fb10f2dfdaa035102203287878692974d8e49d7eb58b3e2ca23ef3c48771
4
+ data.tar.gz: b01ecf96d3d126ac886af1bf9f66ec41244654740039ed8060aaa59c43f989bf
5
5
  SHA512:
6
- metadata.gz: d4e1b9ee7c969e217846bc6d9a1e6c896659915e10ff2aaa631b3db1c28d14def8ed2e138ca1701b86fc8cd3246e9dc0b8c73647bf6f0263a9c4f176934022f5
7
- data.tar.gz: f7ac382605f8662528d1e27b2936ac7530dec4e96ef852a51435e70dc48b1327fa064c4d9bd868436057d9deb3ca6edacaadfe53794ec1eac3d60310dbbfe318
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,25 +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',
38
+ def initialize(txt, level: nil, ignore_blank_lines: false,
39
+ abort_1_row: false, debug: false, name: 'item',
40
40
  allow_lonely_keyfield: false)
41
-
41
+
42
42
  @name, @debug = name, debug
43
-
44
- # auto indent any multiline values
45
-
43
+
44
+ # auto indent any multiline values
45
+
46
46
  indent = ''
47
47
 
48
48
  lines = txt.gsub(/^-+$/m,'').lines.map do |line|
@@ -55,10 +55,10 @@ class RowX
55
55
  end
56
56
 
57
57
  end
58
-
58
+
59
59
  puts 'lines: ' + lines.inspect if @debug
60
60
 
61
- a = LineTree.new(lines.join, level: level,
61
+ a = LineTree.new(lines.join, level: level,
62
62
  ignore_blank_lines: ignore_blank_lines, debug: debug).to_a
63
63
  puts ('a: ' + a.inspect).debug if @debug
64
64
 
@@ -66,23 +66,23 @@ class RowX
66
66
  puts ('keyfield: ' + keyfield.inspect).debug if @debug
67
67
 
68
68
  if not allow_lonely_keyfield then
69
-
70
- # find the keyfield. if there's only 1 keyfield in all of the rows it's
69
+
70
+ # find the keyfield. if there's only 1 keyfield in all of the rows it's
71
71
  # not a keyfield. Keep searching until all rows have been searched
72
72
  while a.select {|x| x[0][/^#{keyfield}/]}.length <= 1 and \
73
73
  i < a.length and a[i+1]
74
-
74
+
75
75
  i += 1
76
76
  keyfield = a[i][0][/\w+/]
77
77
 
78
78
  end
79
-
79
+
80
80
  end
81
-
81
+
82
82
  keyfield = a[0][0][/\w+/] if i == a.length - 1
83
83
 
84
84
  if a.flatten(1).grep(/^#{keyfield}/).length == 1 then # only 1 record
85
- i = 0
85
+ i = 0
86
86
  raise RowXException, 'Expected more than 1 row' if abort_1_row
87
87
  end
88
88
 
@@ -90,43 +90,43 @@ class RowX
90
90
 
91
91
  summary = scan_a a.slice!(0,i)
92
92
  summary[0] = 'summary'
93
-
93
+
94
94
  @rexle_a = scan_records(records, level)
95
95
  @to_a = ['root', {}] + [summary] + @rexle_a
96
96
  @to_xml = Rexle.new(@to_a).xml pretty: true
97
97
 
98
98
  end
99
-
99
+
100
100
  def to_lines(delimiter: ' # ')
101
101
  @rexle_a.map {|x| x[3..-1].map {|y| y[2]}.join(delimiter)}.join("\n").lines
102
102
  end
103
103
 
104
104
  private
105
-
105
+
106
106
 
107
107
  def scan_a(row)
108
108
 
109
109
  a = row.map do |field|
110
-
110
+
111
111
  puts 'field: ' + field.inspect if @debug
112
112
  s = field.is_a?(Array) ? field[0] : field
113
113
 
114
114
  return if s.empty?
115
115
  puts 's: ' + s.inspect if @debug
116
- found = s.match(/^(\w+)(?:\:$|\:\s+)(.*)/m)
116
+ found = s.match(/^(\w+)(?:\:$|\:\s*)(.*)/m)
117
117
 
118
- value, name = found ? found.captures.reverse : s
118
+ value, name = found ? found.captures.reverse : s
119
119
  name ||= 'description'
120
-
121
- children = scan_a(field[1..-1]) if field[-1] .is_a?(Array)
122
- value = value.to_s.strip.gsub('<','&lt;').gsub('>','&gt;')
120
+
121
+ children = scan_a(field[1..-1]) if field[-1] .is_a?(Array)
122
+ value = value.to_s.strip.gsub('<','&lt;').gsub('>','&gt;')
123
123
 
124
124
  # it's a line which has been commented out?
125
125
  if name[0] == '#' then
126
126
  value = name[1..-1] + ': ' + value
127
- name = '!-'
127
+ name = '!-'
128
128
  end
129
-
129
+
130
130
  result = [name, {}, value]
131
131
  result << children if children
132
132
  result
@@ -136,7 +136,7 @@ class RowX
136
136
  end
137
137
 
138
138
  def scan_records(rows, level)
139
-
139
+
140
140
  rows.map {|x| scan_a x }
141
141
 
142
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.7.4
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
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAxMDAyMTcwMzA2WhcN
15
- MjExMDAyMTcwMzA2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCxdWYo
17
- ZJh+h0r6SSXVW4Bn5epCBXzD5ponWVz4Z1njTRsB0b2gSge1JK3Z4XXMhaFqm5jR
18
- 8/5PUQNiZUNqklf6qY1vz9yF3UdktAZW2yFbFlh1TypMyx733Vr2v8c9RDYBraXb
19
- WQEl2Ux2JhM9w0AOm6a0uTCiXhxj9KOJfa9b5FyvWkL9UXgUSb6oz+vOqFUKjv1M
20
- FpKSUgaN2jfbggB7VeceH2xZ10MYLG6WwFp3rIEjMltwbBUsZqaZiHMFMujf8TKq
21
- 76eDWsSBJ+AmWccrfiwAlSTsJqPuz9HimBSQUAJJlqA3z44T5f+1EtZx+fzvD9m4
22
- k/uSlOFK1U3U080yb4S7o5AhOErZWY/D0DupIv/IasgYtPSCQ92JihIjx4WSn3ID
23
- iW4GIUjEyOL0PJBYA3yn4NjcVw2sBrduX1k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bx
33
+ wusUvr5gPBCocxOnqPbKdOLOWGuHoVe6pKaUFFxVBj2R1dC/ErqNMdj0AxQoSgTi
34
+ aDvs3bDHPgW1IHO4PWdeXr8KBfTIr1n0qrZ1IF4rNeTiTf4Pqo7x8VrpvNN3sG6/
35
+ kfXR2KNu3kHN0g9PsBdrL79ctMBurBHn/ATYdhoOG4ebjY2ubJz5nR9sOONJUroJ
36
+ AB0aDh+E6dzxvdb+vmfSBHJb
37
37
  -----END CERTIFICATE-----
38
- date: 2020-10-04 00:00:00.000000000 Z
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.1
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.1
59
+ version: 0.9.3
60
60
  description: Generates XML from rows of labelled text, nested text, and plain text
61
- email: james@jamesrobertson.eu
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
- rubygems_version: 3.0.3
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