pikelet 2.0.0.beta.8 → 2.0.0.beta.9
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/README.md +20 -0
- data/lib/pikelet/field_definition.rb +2 -1
- data/lib/pikelet/version.rb +1 -1
- data/spec/pikelet/field_definition_spec.rb +1 -1
- data/spec/readme_examples_spec.rb +119 -0
- 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: 58194d17548297f7e8d35fbb76d5ffdb5588a715
|
4
|
+
data.tar.gz: 18bc08e057dc9c91767445a1303800e7e0726e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc2a341e268794105b79104a91f18b25a5a3eaf9f3fbafa49cfe796dc56cd6d432aef249c1622715ab18453f9a2c5787f9e2051b50bdf22c2c228440607f0ea
|
7
|
+
data.tar.gz: d3353fdb052dd8de520c6575ea06d10940ab9606412789fb93ed63b13c80a4732580b6eade95e9e4a7b6a1f7d01989fb5310bd9727a9500cd4209f2b40408040
|
data/README.md
CHANGED
@@ -295,6 +295,26 @@ a custom class to use instead.
|
|
295
295
|
|
296
296
|
The only requirement on the class is that its constructor (ie. `initialize`
|
297
297
|
method) should accept attributes as a hash with symbol keys.
|
298
|
+
|
299
|
+
### Legacy type signature syntax
|
300
|
+
|
301
|
+
In Pikelet v1.x there wasn't a `signature_field` option. Instead, you were
|
302
|
+
required to name your signature field `type_signature`.
|
303
|
+
|
304
|
+
Pikelet.define do
|
305
|
+
type_signature 0...4
|
306
|
+
|
307
|
+
record "NAME" do
|
308
|
+
first_name 4...14
|
309
|
+
last_name 14...24
|
310
|
+
end
|
311
|
+
|
312
|
+
record "ADDR" do
|
313
|
+
street_address 4...24
|
314
|
+
city 24...44
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
298
318
|
## Thoughts/plans
|
299
319
|
|
300
320
|
* I had a crack at supporting lazy enumeration, and it kinda works. Sometimes.
|
data/lib/pikelet/version.rb
CHANGED
@@ -16,7 +16,7 @@ describe Pikelet::FieldDefinition do
|
|
16
16
|
|
17
17
|
subject { definition }
|
18
18
|
|
19
|
-
its(:parser) { is_expected.to
|
19
|
+
its(:parser) { is_expected.to be_nil }
|
20
20
|
its(:formatter) { is_expected.to eq :to_s }
|
21
21
|
its(:padding) { is_expected.to eq " " }
|
22
22
|
its(:alignment) { is_expected.to eq :left }
|
@@ -174,4 +174,123 @@ describe "README Examples:" do
|
|
174
174
|
|
175
175
|
it_will "format the records"
|
176
176
|
end
|
177
|
+
|
178
|
+
describe "Formatting options" do
|
179
|
+
let(:definition) do
|
180
|
+
Pikelet.define do
|
181
|
+
number 0... 3, align: :right, pad: "0"
|
182
|
+
text 3...10, align: :left, pad: "-"
|
183
|
+
another_number 10...13, type: :numeric
|
184
|
+
more_text 13...20, type: :alpha
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
let(:records) do
|
189
|
+
[
|
190
|
+
OpenStruct.new(number: 9, text: "blah", another_number: 12, more_text: "meh")
|
191
|
+
]
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:expected_data) do
|
195
|
+
<<-DATA
|
196
|
+
|009|blah---|012|meh |
|
197
|
+
DATA
|
198
|
+
end
|
199
|
+
|
200
|
+
it_will "format the records"
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "Custom record classes" do
|
204
|
+
class Base
|
205
|
+
attr_reader :type
|
206
|
+
|
207
|
+
def initialize(**attrs)
|
208
|
+
@type = attrs[:type]
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class Name < Base
|
213
|
+
attr_reader :name
|
214
|
+
|
215
|
+
def initialize(**attrs)
|
216
|
+
super(type: "NAME")
|
217
|
+
@name = attrs[:name]
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
class Address < Base
|
222
|
+
attr_reader :street, :city
|
223
|
+
|
224
|
+
def initialize(**attrs)
|
225
|
+
super(type: "ADDR")
|
226
|
+
@street = attrs[:street]
|
227
|
+
@city = attrs[:city]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
let(:definition) do
|
232
|
+
Pikelet.define signature_field: :type, record_class: Base do
|
233
|
+
type 0...4
|
234
|
+
|
235
|
+
record "NAME", record_class: Name do
|
236
|
+
name 4...20
|
237
|
+
end
|
238
|
+
|
239
|
+
record "ADDR", record_class: Address do
|
240
|
+
street 4...20
|
241
|
+
city 20...30
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
let(:data) do
|
247
|
+
<<-DATA
|
248
|
+
|NAME|Frida Kahlo |
|
249
|
+
|ADDR|123 South Street|Sometown |
|
250
|
+
DATA
|
251
|
+
end
|
252
|
+
|
253
|
+
let(:expected_records) do
|
254
|
+
[
|
255
|
+
{ class: Name, type: "NAME", name: "Frida Kahlo" },
|
256
|
+
{ class: Address, type: "ADDR", street: "123 South Street", city: "Sometown" }
|
257
|
+
]
|
258
|
+
end
|
259
|
+
|
260
|
+
it_will "parse the data"
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "Legacy type signature syntax" do
|
264
|
+
let(:definition) do
|
265
|
+
Pikelet.define do
|
266
|
+
type_signature 0...4
|
267
|
+
|
268
|
+
record "NAME" do
|
269
|
+
first_name 4...14
|
270
|
+
last_name 14...24
|
271
|
+
end
|
272
|
+
|
273
|
+
record "ADDR" do
|
274
|
+
street_address 4...24
|
275
|
+
city 24...44
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
let(:data) do
|
281
|
+
<<-DATA
|
282
|
+
|NAME|Frida |Kahlo |
|
283
|
+
|ADDR|123 South Street |Sometown |
|
284
|
+
DATA
|
285
|
+
end
|
286
|
+
|
287
|
+
let(:expected_records) do
|
288
|
+
[
|
289
|
+
{ type_signature: "NAME", first_name: "Frida", last_name: "Kahlo" },
|
290
|
+
{ type_signature: "ADDR", street_address: "123 South Street", city: "Sometown" }
|
291
|
+
]
|
292
|
+
end
|
293
|
+
|
294
|
+
it_will "parse the data"
|
295
|
+
end
|
177
296
|
end
|