textutils 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b0282aa2a7a821c25f24b39dd50a4486d3d3a68
4
- data.tar.gz: 5d7c21778e9c4f3ebfec10bdcf18c861a84fd31a
3
+ metadata.gz: d5ec47749fc531cb8ffbc71fc152c2a31e53e637
4
+ data.tar.gz: eb485b1f3e40c1a8653f3a5d19e17a0d30b3079c
5
5
  SHA512:
6
- metadata.gz: 703c28f053cbc841cbcaffcecafab2896b5756be3a4a33b53bb0fc6fe83d310f5c249690301916343724ad1819c4c21b0f27a37d26702a7e109ab4aa87fc0070
7
- data.tar.gz: 61d6e63ca7cbdc13ea4c70ee82ef3282835a71ccd29e04da8a7af5657398c81ed4f3c04ccbd2c7cd79dd7a77b2b8d6d1def52674a926f2e1c2a51fa56af3f491
6
+ metadata.gz: 574f8628d2bebd407b0ee4846be97833d840cc734dcccb137d8eb64cdc5b2498a70888e15b22a6f118501dbc8bf1cbf72ed1d01ab0f02d0f186b6bbcf3251d68
7
+ data.tar.gz: 59f803dc2c934437730986b542e11be3b79d96c563406badd80a5b06c70474d82c282b6565f1cd8f3733867b37385e2bcb1cf06407223b98675ac7bb8c9ae511
@@ -113,7 +113,13 @@ class ValuesReader
113
113
  ## NOTE: for now alternative comment lines not allowed as end of line style e.g
114
114
  ## some data, more data -- comment here
115
115
 
116
- if line =~ /^\s*#/ ||
116
+ ######
117
+ ## note:
118
+ ## # comment MUST follow a space or end-of-line e.g.
119
+ ## #1 or #hello or #(hello) or #{hello} is NOT a comment
120
+ ## ###### is however
121
+
122
+ if line =~ /^\s*#+(\s|$)/ || # old - simple rule -- /^\s*#/
117
123
  line =~ /^\s*--/ ||
118
124
  line =~ /^\s*%/ ||
119
125
  line =~ /^\s*__/
@@ -129,26 +135,31 @@ class ValuesReader
129
135
  next
130
136
  end
131
137
 
132
- ### NOTE: skip sections lines (marked w/ at least ==) for now
133
- ### e.g. === Waldviertel ===
134
- if line =~ /^\s*={2,}\s+/
135
- logger.debug "skipping section line |»#{line}«|"
136
- next
137
- end
138
-
139
-
140
138
  # pass 1) remove possible trailing eol comment
141
139
  ## e.g -> nyc, New York # Sample EOL Comment Here (with or without commas,,,,)
142
140
  ## becomes -> nyc, New York
141
+ #
142
+ ## note - comment must follow a space or end-of-line
143
+ # #1 or #hello or #{hello} is NOT a comment !!!
144
+ # note ###### is a comment
143
145
 
144
- line = line.sub( /\s+#.+$/, '' )
146
+ line = line.sub( /\s+#+(\s.+)?$/, '' )
145
147
 
146
148
  # pass 2) remove leading and trailing whitespace
147
-
149
+
148
150
  line = line.strip
149
151
 
150
152
 
151
- if line =~ /^-\s+/ # check for group headers e.g. - St. James Brewery
153
+
154
+
155
+ ### NOTE: skip sections lines (marked w/ at least ==) for now
156
+ ### e.g. === Waldviertel ===
157
+ if line =~ /^\s*={2,}\s+/
158
+ logger.debug "skipping section line |»#{line}«|"
159
+ next
160
+ end
161
+
162
+ if line =~ /^-\s+/ # check for group headers (MUST start w/ dash (-) e.g. - St. James Brewery)
152
163
  if values.length > 0 # check if we already processed a record? if yes; yield last record (before reset)
153
164
  attribs, more_values = find_key_n_title( values )
154
165
  attribs = attribs.merge( @more_attribs ) # e.g. merge country_id and other defaults if present
@@ -160,14 +171,16 @@ class ValuesReader
160
171
  blank_counter = 0
161
172
 
162
173
  # update last_header
163
- last_header = line.gsub( /^-\s/, '' ) # cut-off leading marker and space
174
+ last_header = line.sub( /^-\s+/, '' ) # cut-off leading marker and space
164
175
  logger.info " update group header >#{last_header}<"
165
176
  next
166
- elsif line =~ /^\[([a-z][a-z]+)\]/
167
- ### check for multiline record
168
- ## must start with key e.g. [guiness]
169
- ## for now only supports key with letter a-z (no digits/numbers or underscore or dots)
170
-
177
+ end
178
+
179
+
180
+ if line =~ /^\[(.+)\]$/ # note: check for multiline record; MUST start w/ [ and end w/ ]
181
+
182
+ value = $1.strip # note: remove (allow) possible leading n trailing spaces
183
+
171
184
  if values.length > 0 # check if we already processed a record? if yes; yield last record (before reset)
172
185
  attribs, more_values = find_key_n_title( values )
173
186
  attribs = attribs.merge( @more_attribs ) # e.g. merge country_id and other defaults if present
@@ -180,9 +193,9 @@ class ValuesReader
180
193
 
181
194
  # NB: every additional line is one value e.g. city:wien, etc.
182
195
  # allows you to use any chars
183
- logger.debug " multi-line record w/ key »#{$1}«"
196
+ logger.debug " start multi-line record w/ »#{value}«"
184
197
 
185
- values = [$1.dup] # add key as first value in ary
198
+ values = [value] # add as first value in ary - note: find_key_n_title will check if value is a key or not
186
199
  elsif inside_record && blank_counter == 0 && line =~ /\/{2}/ # check address line (must contain //)
187
200
  values += [line.dup] # assume single value column (no need to escape commas)
188
201
  elsif inside_record && blank_counter == 0 && line =~ /^[a-z][a-z0-9.]*[a-z0-9]:/ # check key: value pair
@@ -245,26 +258,9 @@ class ValuesReader
245
258
 
246
259
  values = values.map { |value| value.strip }
247
260
 
248
-
249
- ##### todo/fix:
250
- # !!!REMOVE!!!
251
- # remove support of comment column? (NB: must NOT include commas)
252
- # pass 2) remove comment columns
253
- #
254
- # todo/fix: check if still possible ?? - add an example here how it looks like/works
255
-
256
- values = values.select do |value|
257
- if value =~ /^#/ ## start with # treat it as a comment column; e.g. remove it
258
- logger.info " removing column with value »#{value}«"
259
- false
260
- else
261
- true
262
- end
263
- end
264
-
265
261
  logger.debug " values: |»#{values.join('« »')}«|"
266
262
  values
267
263
  end
268
264
 
269
265
 
270
- end # class ValuesReader
266
+ end # class ValuesReader
@@ -3,8 +3,8 @@
3
3
  module TextUtils
4
4
 
5
5
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 0
7
- PATCH = 1
6
+ MINOR = 1
7
+ PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props