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 +4 -4
- data/lib/textutils/reader/values_reader.rb +49 -6
- data/lib/textutils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e40ccfbcb833b42ca09205ad659db438c5205c2
|
4
|
+
data.tar.gz: 2025fd82b7f254c303bc900e59441b571a9cf543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
268
|
+
attribs[:values] = more_values
|
269
|
+
attribs[:meta] = meta
|
270
|
+
yield( attribs )
|
228
271
|
end
|
229
272
|
|
230
273
|
end # method each_line
|
data/lib/textutils/version.rb
CHANGED