textutils 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ec47749fc531cb8ffbc71fc152c2a31e53e637
4
- data.tar.gz: eb485b1f3e40c1a8653f3a5d19e17a0d30b3079c
3
+ metadata.gz: 3e40ccfbcb833b42ca09205ad659db438c5205c2
4
+ data.tar.gz: 2025fd82b7f254c303bc900e59441b571a9cf543
5
5
  SHA512:
6
- metadata.gz: 574f8628d2bebd407b0ee4846be97833d840cc734dcccb137d8eb64cdc5b2498a70888e15b22a6f118501dbc8bf1cbf72ed1d01ab0f02d0f186b6bbcf3251d68
7
- data.tar.gz: 59f803dc2c934437730986b542e11be3b79d96c563406badd80a5b06c70474d82c282b6565f1cd8f3733867b37385e2bcb1cf06407223b98675ac7bb8c9ae511
6
+ metadata.gz: 06e3600e5bb04eb77f5b13f11a9fa757ea0731196f15c327943d8b0b188b4c05e2666684ca97f2369b8526b991f8faf9bd0a23291727a9effa30ca10c99f3ebb
7
+ data.tar.gz: 786f1feabf6f40cac7c23122e6052d94ba8011bd3170d9b48529e89e808c2a4a2963132043a145ccd80c96bc4afb91a7297ba7673794828739182e51d00b1087
@@ -86,11 +86,40 @@ class ValuesReader
86
86
  # and so on - lets us reuse code for tags and more
87
87
 
88
88
 
89
- def each_line # support multi line records
89
+ def each_line # old style w/o meta hash -- rename to each_record - why, why not???
90
+ each_line_with_meta do |attribs|
91
+ ## remove meta
92
+ if attribs[:meta].present?
93
+ attribs.delete(:meta)
94
+ end
95
+
96
+ ## (more) values array entry - make top level
97
+ values = attribs[:values]
98
+ attribs.delete(:values)
99
+
100
+ yield( attribs, values )
101
+ end
102
+ end
103
+
104
+
105
+ def each_line_with_meta # support multi line records -- rename to each_record_with_ - why, why not??
90
106
 
91
107
  inside_record = false
92
108
  blank_counter = 0 # count of number of blank lines (note: 1+ blank lines clear multi-line record)
93
109
  values = []
110
+ meta = {}
111
+
112
+ ###
113
+ # meta
114
+ # use format or style key ??
115
+ # use line|multiline or classic|modern or csv|csv+ etc.??
116
+ #
117
+ # move header to meta (from top-level) - why, why not ??
118
+ # or use context for header and sections etc.????
119
+ # move section to meta - why, why not ??
120
+ #
121
+ # might add lineno etc. in future??
122
+
94
123
 
95
124
  # keep track of last header
96
125
  # e.g. lines like
@@ -164,8 +193,11 @@ class ValuesReader
164
193
  attribs, more_values = find_key_n_title( values )
165
194
  attribs = attribs.merge( @more_attribs ) # e.g. merge country_id and other defaults if present
166
195
  attribs[:header] = last_header unless last_header.nil? # add optional header attrib
167
- yield( attribs, more_values )
196
+ attribs[:values] = more_values
197
+ attribs[:meta] = meta
198
+ yield( attribs )
168
199
  values = []
200
+ meta = {}
169
201
  end
170
202
  inside_record = false
171
203
  blank_counter = 0
@@ -185,11 +217,15 @@ class ValuesReader
185
217
  attribs, more_values = find_key_n_title( values )
186
218
  attribs = attribs.merge( @more_attribs ) # e.g. merge country_id and other defaults if present
187
219
  attribs[:header] = last_header unless last_header.nil? # add optional header attrib
188
- yield( attribs, more_values )
220
+ attribs[:values] = more_values
221
+ attribs[:meta] = meta
222
+ yield( attribs )
189
223
  values = []
224
+ meta = {}
190
225
  end
191
226
  inside_record = true
192
227
  blank_counter = 0
228
+ meta[:format] = :multiline # use :modern - why, why not?
193
229
 
194
230
  # NB: every additional line is one value e.g. city:wien, etc.
195
231
  # allows you to use any chars
@@ -199,6 +235,7 @@ class ValuesReader
199
235
  elsif inside_record && blank_counter == 0 && line =~ /\/{2}/ # check address line (must contain //)
200
236
  values += [line.dup] # assume single value column (no need to escape commas)
201
237
  elsif inside_record && blank_counter == 0 && line =~ /^[a-z][a-z0-9.]*[a-z0-9]:/ # check key: value pair
238
+ ### todo: split key n value and add to attrib hash - why, why not???
202
239
  values += [line.dup] # assume single value column (no need to escape commas)
203
240
  else
204
241
  if inside_record && blank_counter == 0 # continue adding more values
@@ -208,12 +245,16 @@ class ValuesReader
208
245
  attribs, more_values = find_key_n_title( values )
209
246
  attribs = attribs.merge( @more_attribs ) # e.g. merge country_id and other defaults if present
210
247
  attribs[:header] = last_header unless last_header.nil? # add optional header attrib
211
- yield( attribs, more_values )
248
+ attribs[:values] = more_values
249
+ attribs[:meta] = meta
250
+ yield( attribs )
212
251
  values = []
252
+ meta = {}
213
253
  end
214
254
  inside_record = false
215
255
  blank_counter = 0
216
- values = find_values( line )
256
+ meta[:format] = :line # use :classic - why, why not?
257
+ values = find_values( line )
217
258
  end
218
259
  end
219
260
 
@@ -224,7 +265,9 @@ class ValuesReader
224
265
  attribs, more_values = find_key_n_title( values )
225
266
  attribs = attribs.merge( @more_attribs ) # e.g. merge country_id and other defaults if present
226
267
  attribs[:header] = last_header unless last_header.nil? # add optional header attrib
227
- yield( attribs, more_values )
268
+ attribs[:values] = more_values
269
+ attribs[:meta] = meta
270
+ yield( attribs )
228
271
  end
229
272
 
230
273
  end # method each_line
@@ -3,7 +3,7 @@
3
3
  module TextUtils
4
4
 
5
5
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 1
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer