rubyment 0.7.25752271 → 0.7.25752540

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubyment.rb +140 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fba539ff6f78991f287f12e659693ed5a2a1bdd
4
- data.tar.gz: 32dcb1fb4062d6de26fd7319bd42b480fc72888f
3
+ metadata.gz: d6fbbb8b232ca1a58d1440b3310dc2a87a5c6f30
4
+ data.tar.gz: 459ab366a552afb2fe23f31ecb2e8030842d0002
5
5
  SHA512:
6
- metadata.gz: a0cbf91c10a8c2b630c457a446d307244fb55d1aeb5ac7592b1a31b26a3cb823a8522150937c465b63368df39806dfb5f86cf62f9b8dffa142eaffa5bb934b5e
7
- data.tar.gz: 880fee67876c2d3cf7b982aafe0acc191ac221398a30adb24ff495014f8e2cfb2615d106f5d7a6a16cc04b8ecc77213772b3b46915418da9231f4f5fc51dcae8
6
+ metadata.gz: f8f6bb176e2bed86d86faa13f7c66755fef1adc4c7b64fc95a854d80b93a2697678289b9126f15b76fab6d762225cb7546b8fd3da1a55d7b57b97eba4ec7f93d
7
+ data.tar.gz: 8d2795d66b35b4c1f6670d1aedb69dda3ae65757c39f029f03bb7f372d0b72568a03e4040ca8ddda68eed11f55d545bd9a4edefe85383b72038c1807c8f6efda
@@ -318,6 +318,146 @@ module RubymentStringsModule
318
318
  end
319
319
 
320
320
 
321
+ =begin
322
+ Makes possible to join, similarly to Array#join, recursively.
323
+
324
+ Note of difference in behavior:
325
+
326
+ [ "", "" ].join "+"
327
+ # => "+"
328
+
329
+ [ nil, nil ].join "+"
330
+ # => "+"
331
+
332
+ In this function, empty strings are not joinned
333
+ (.nne and .compact are run before). It's a planned
334
+ change to expand the interface to be able to
335
+ instruct for not nne/compact strings/arrays before.
336
+ TODO: via inheritable joinner; possibly indenter
337
+
338
+ Examples:
339
+
340
+ string__recursive_join ["+", 1, 2, 3 ]
341
+ # => "1+2+3"
342
+
343
+ string__recursive_join [ "; ", ["+", 1, 2, 3 ], ["-", 2, 1] ]
344
+ # => "1+2+3; 2-1"
345
+
346
+ string__recursive_join [ "; ", ["+", 1, ["/", "a", "b"], 3 ], ["-", 2, 1] ]
347
+ # => "1+a/b+3; 2-1"
348
+
349
+
350
+
351
+ =end
352
+ def string__recursive_join joinner_arrays_tuple
353
+ return joinner_arrays_tuple if (
354
+ joinner_arrays_tuple.respond_to?(:map).negate_me
355
+ )
356
+
357
+ joinner,
358
+ *operands = joinner_arrays_tuple
359
+ operands.map! { |operand|
360
+ (
361
+ send __method__, operand # recursive call
362
+ ).nne
363
+ }
364
+
365
+ operands.compact.join(joinner)
366
+ end
367
+
368
+
369
+ =begin
370
+ If definition cannot map, retuns itself.
371
+
372
+ Otherwise, it will generate a string out of the values
373
+ given in that array, which can describe, for instance,
374
+ recursive expressions. Better explained by examples:
375
+
376
+ Examples:
377
+
378
+ string__from_definition [ "value", "var" ]
379
+ # => "var value"
380
+
381
+ string__from_definition [ "value" ]
382
+ # => "value"
383
+
384
+ string__from_definition [ "value", ["var"], "=" ]
385
+ # => "var=value"
386
+
387
+ string__from_definition [ "value", ["var"], "" ]
388
+ # => "varvalue"
389
+
390
+ string__from_definition [ nil, ["var"], "=" ]
391
+ # => "var="
392
+
393
+ string__from_definition [ "value", ["var", "EXPORT"], "=" ]
394
+ # => "EXPORT var=value"
395
+
396
+ string__from_definition [ ["value"], ["var", "EXPORT"], "=" ]
397
+ # => "EXPORT var=value"
398
+
399
+ string__from_definition ["value", nil, nil, nil, "`", "`"]
400
+ # => "`value`"
401
+
402
+ string__from_definition [ ["value", nil, nil, nil, "`", "`"] , ["var", "EXPORT"], "=" ]
403
+ # => "EXPORT var=`value`"
404
+
405
+ # ----- test the spacer:
406
+
407
+ string__from_definition [ "value", ["var"], "=", "," ]
408
+ # => "var,=,value"
409
+
410
+ string__from_definition [ "value", ["var"], nil, "," ]
411
+ # => "var, ,value"
412
+
413
+ string__from_definition [ "value", ["var"], "", "," ]
414
+ # => "var,value"
415
+
416
+ string__from_definition [ " ... describe here ... ", "contents:", "", "\n", "# begin section", "# end section "]
417
+ # => "# begin section\ncontents:\n ... describe here ... \n# end section "
418
+
419
+
420
+ =end
421
+ def string__from_definition definition
422
+ return definition if (
423
+ definition.respond_to?(:map).negate_me
424
+ )
425
+
426
+ value,
427
+ variable,
428
+ operation,
429
+ spacer,
430
+ open,
431
+ close,
432
+ reserved = definition.map { |d|
433
+ send __method__, d # recursive call
434
+ }
435
+
436
+ # if variable is non empty, the default operation is "="
437
+ # of course, only applied if operation is not set
438
+ # A priori, nne not to be used, otherwise "" operation
439
+ # won't be allowed
440
+ operation ||= (variable && " " || "")
441
+ spacer = spacer.nne ""
442
+ variable = variable.nne ""
443
+
444
+ rv = string__recursive_join [
445
+ spacer, # separator
446
+ open,
447
+ [
448
+ spacer, # separator
449
+ variable,
450
+ operation,
451
+ value,
452
+ ],
453
+ close,
454
+ ]
455
+
456
+ rv
457
+
458
+ end
459
+
460
+
321
461
  end # of RubymentStringsModule
322
462
 
323
463
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.25752271
4
+ version: 0.7.25752540
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribamar Santarosa