hash-utils 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- script: "rake test"
1
+ script: "rake test --trace"
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 1.9.2
@@ -10,7 +10,3 @@ rvm:
10
10
  - jruby-head
11
11
  - 1.8.7
12
12
  - ree
13
- jdk:
14
- - openjdk7
15
- - oraclejdk7
16
- - openjdk6
@@ -1,4 +1,14 @@
1
1
 
2
+ 2.1.0 (2012-11-24)
3
+ * most of missing tests
4
+ * a lot of compatibility problems fixed
5
+ * specs (tests) to standard file structure
6
+ * Hash: #some?, #some_pairs? bug fix
7
+ * Array: #merge! optimization
8
+ * Array: #complete_to, #complete_to!, #cut, #cut!, #drop!, #expand_by,
9
+ #expand_by!, #interlace, #interlace!, #shrink_to, #shrink_to!, #zip!
10
+ * Symbol: #<=>
11
+
2
12
  2.0.2 (2012-10-06)
3
13
  * String: #first compatiblity problem with 1.8 fixed
4
14
  * StringIO: compatiblity problem with Rubinius 1.9 fixed
@@ -61,9 +71,9 @@
61
71
  * Object: #instance_of_any?, #kind_of_any?
62
72
 
63
73
  0.15.0 (2011-05-30)
64
- * Hash#keys_to_sym now converts only strings
65
- * Hash#to_h bug correction
66
- * Hash#all? removed in favour built-in one
74
+ * Hash: #keys_to_sym now converts only strings
75
+ * Hash: #to_h bug correction
76
+ * Hash: #all? removed in favour built-in one
67
77
  * Hash: #get, #get_items, #get_values
68
78
  * Symbol: #split
69
79
  * Array: #first, #second, #third, #fourth, #fifth, #sixth,
@@ -9,23 +9,23 @@ GEM
9
9
  rake
10
10
  rdoc
11
11
  json (1.7.5)
12
- multi_json (1.3.6)
13
- rake (0.9.2.2)
12
+ multi_json (1.4.0)
13
+ rake (10.0.2)
14
14
  rdoc (3.12)
15
15
  json (~> 1.4)
16
- rspec (2.11.0)
17
- rspec-core (~> 2.11.0)
18
- rspec-expectations (~> 2.11.0)
19
- rspec-mocks (~> 2.11.0)
20
- rspec-core (2.11.1)
21
- rspec-expectations (2.11.3)
16
+ rspec (2.12.0)
17
+ rspec-core (~> 2.12.0)
18
+ rspec-expectations (~> 2.12.0)
19
+ rspec-mocks (~> 2.12.0)
20
+ rspec-core (2.12.1)
21
+ rspec-expectations (2.12.0)
22
22
  diff-lcs (~> 1.1.3)
23
- rspec-mocks (2.11.3)
24
- ruby-version (0.4.2)
25
- simplecov (0.6.4)
23
+ rspec-mocks (2.12.0)
24
+ ruby-version (0.4.3)
25
+ simplecov (0.7.1)
26
26
  multi_json (~> 1.0)
27
- simplecov-html (~> 0.5.3)
28
- simplecov-html (0.5.3)
27
+ simplecov-html (~> 0.7.1)
28
+ simplecov-html (0.7.1)
29
29
 
30
30
  PLATFORMS
31
31
  ruby
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  Hash Utils
2
2
  ==========
3
3
 
4
- **hash-utils** adds more than 135 useful and frequently rather
4
+ **hash-utils** gem adds more than 155 useful and frequently rather
5
5
  fundamental methods which are missing in Ruby programming language,
6
6
  to several core classes. It tries to be similar project to
7
7
  [Ruby Facets][1] on principle, but less complex, more practical,
8
8
  non-atomic and organized by better way.
9
9
 
10
- - `Array` &ndash; 15 methods,
10
+ - `Array` &ndash; 27 methods,
11
11
  - `FalseClass` &ndash; 3 methods,
12
12
  - `File` &ndash; 2 methods,
13
13
  - `Gem` &ndash; 2 methods,
@@ -18,12 +18,13 @@ non-atomic and organized by better way.
18
18
  - `Numeric` &ndash; 5 method,
19
19
  - `Object` &ndash; 15 methods,
20
20
  - `Proc` &ndash; 1 method,
21
- - `TrueClass` &ndash; 3 methods,
22
21
  - `String` &ndash; 37 methods,
23
22
  - `StringIO` &ndash; 1 method,
24
- - `Symbol` &ndash; 8 methods.
23
+ - `Symbol` &ndash; 9 methods,
24
+ - `TrueClass` &ndash; 3 methods.
25
25
 
26
26
  For full reference and methods lists, see **[documentation][3]**.
27
+
27
28
  [![Build Status](https://secure.travis-ci.org/martinkozak/hash-utils.png)](http://travis-ci.org/martinkozak/hash-utils)
28
29
 
29
30
  ### Modularization
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.name = "hash-utils"
21
21
  gem.homepage = "http://github.com/martinkozak/hash-utils"
22
22
  gem.license = "MIT"
23
- gem.summary = 'Adds more than 135 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way. Thanks to defensive and careful patching it should be compatible with all other libraries.'
23
+ gem.summary = 'Adds more than 155 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way. Thanks to defensive and careful patching it should be compatible with all other libraries.'
24
24
  #gem.post_install_message = "\nHASH UTILS: The 2.0 version avoids the method overwriting conflicts by not performing overwriting of already implemented methods. By this way, it can damage your existing applications based on older versions although it's very improbable. \n\n"
25
25
  gem.email = "martinkozak@martinkozak.net"
26
26
  gem.authors = ["Martin Kozák"]
@@ -37,6 +37,5 @@ Jeweler::RubygemsDotOrgTasks.new
37
37
  require 'rspec/core/rake_task'
38
38
 
39
39
  RSpec::Core::RakeTask.new(:test) do |t|
40
- t.pattern = 'tests.rb'
41
40
  t.rspec_opts = '--format d -c'
42
41
  end
data/TODO.txt CHANGED
@@ -1,3 +1,2 @@
1
1
  * add examples to each call
2
- * write remaining tests
3
2
  * integrate functions from http://rubydoc.info/gems/sane/0.25.5/frames
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hash-utils"
8
- s.version = "2.0.2"
8
+ s.version = "2.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Martin Koz\u{e1}k"]
12
- s.date = "2012-10-06"
12
+ s.date = "2012-12-04"
13
13
  s.email = "martinkozak@martinkozak.net"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -42,13 +42,26 @@ Gem::Specification.new do |s|
42
42
  "lib/hash-utils/string.rb",
43
43
  "lib/hash-utils/stringio.rb",
44
44
  "lib/hash-utils/symbol.rb",
45
- "tests.rb"
45
+ "spec/modules/array_spec.rb",
46
+ "spec/modules/false_spec.rb",
47
+ "spec/modules/file_spec.rb",
48
+ "spec/modules/hash_spec.rb",
49
+ "spec/modules/io_spec.rb",
50
+ "spec/modules/module_spec.rb",
51
+ "spec/modules/nil_spec.rb",
52
+ "spec/modules/numeric_spec.rb",
53
+ "spec/modules/object_spec.rb",
54
+ "spec/modules/string_spec.rb",
55
+ "spec/modules/stringio_spec.rb",
56
+ "spec/modules/symbol_spec.rb",
57
+ "spec/modules/true_spec.rb",
58
+ "spec/spec_helper.rb"
46
59
  ]
47
60
  s.homepage = "http://github.com/martinkozak/hash-utils"
48
61
  s.licenses = ["MIT"]
49
62
  s.require_paths = ["lib"]
50
63
  s.rubygems_version = "1.8.24"
51
- s.summary = "Adds more than 135 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way. Thanks to defensive and careful patching it should be compatible with all other libraries."
64
+ s.summary = "Adds more than 155 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way. Thanks to defensive and careful patching it should be compatible with all other libraries."
52
65
 
53
66
  if s.respond_to? :specification_version then
54
67
  s.specification_version = 3
@@ -100,7 +100,7 @@ class Array
100
100
  if not self.__hash_utils_instance_respond_to? :merge!
101
101
  def merge!(*arrays)
102
102
  arrays.flatten! 1
103
- arrays.each { |i| self << i }
103
+ self.push(*arrays)
104
104
  self
105
105
  end
106
106
  end
@@ -296,7 +296,7 @@ class Array
296
296
  end
297
297
 
298
298
  ##
299
- # Converts array to set. Include sets before calling.
299
+ # Converts array to set. Includes sets before calling.
300
300
  #
301
301
  # @return [Set] new set
302
302
  # @since 2.0.0
@@ -307,5 +307,279 @@ class Array
307
307
  Set::new(self)
308
308
  end
309
309
  end
310
+
311
+ ##
312
+ # Performs array members interlacing in place. It means, it inserts
313
+ # given item between members of the array.
314
+ #
315
+ # @example
316
+ # [:a, :b, :c].interlace!("x") # will return [:a, 'x', :b, 'x', :c] which will be in the variable
317
+ #
318
+ # @param [Object] object new member of the array
319
+ # @return [Array] new interlaced array
320
+ # @since 2.1.0
321
+ #
322
+
323
+ if not self.__hash_utils_instance_respond_to? :interlace!
324
+ def interlace!(*objects)
325
+ self.expand_by!(*objects).cut! objects.length
326
+ end
327
+ end
328
+
329
+ ##
330
+ # Performs array members interlacing. It means, it inserts
331
+ # given item between members of the array.
332
+ #
333
+ # @example
334
+ # [:a, :b, :c].interlace("x") # will return [:a, 'x', :b, 'x', :c]
335
+ #
336
+ # @param [Object] object new member of the array
337
+ # @return [Array] new interlaced array
338
+ # @since 2.1.0
339
+ #
340
+
341
+ if not self.__hash_utils_instance_respond_to? :interlace
342
+ def interlace(*objects)
343
+ self.dup.interlace! *objects
344
+ end
345
+ end
346
+
347
+ ##
348
+ # Performs array expanding. It means, it inserts
349
+ # given items after each member of the array.
350
+ #
351
+ # @example
352
+ # [:a, :b, :c].expand_by(1, 2) # will return [:a, 1, 2, :b, 1, 2, :c, 1, 2]
353
+ #
354
+ # @param *[Object] object new member of the array
355
+ # @return [Array] new expanded array
356
+ # @since 2.1.0
357
+ #
358
+
359
+ if not self.__hash_utils_instance_respond_to? :expand_by
360
+ def expand_by(*objects)
361
+ self.dup.expand_by!(*objects)
362
+ end
363
+ end
364
+
365
+ ##
366
+ # Performs array expanding in place. It means, it inserts
367
+ # given items after each member of the array.
368
+ #
369
+ # @example
370
+ # [:a, :b, :c].expand_by(1, 2) # will return [:a, 1, 2, :b, 1, 2, :c, 1, 2]
371
+ #
372
+ # @param *[Object] object new member of the array
373
+ # @return [Array] expanded array
374
+ # @since 2.1.0
375
+ #
376
+
377
+ if not self.__hash_utils_instance_respond_to? :expand_by!
378
+ def expand_by!(*objects)
379
+ if self.empty?
380
+ self
381
+ else
382
+ self.map! { |i| i = [i]; i += objects }.flatten! 1
383
+ end
384
+ end
385
+ end
386
+
387
+ ##
388
+ # Cuts out given portion of the array from the end and returns
389
+ # remaining part in place.
390
+ #
391
+ # @example
392
+ # [1, 2, 3, 4, 5, 6].cut! 2 # will return [1, 2, 3, 4] which also be content of a variable
393
+ #
394
+ # @param [Integer] indexes indexes to cut out
395
+ # @return [Array] resultant array
396
+ # @since 2.1.0
397
+ #
398
+
399
+ if not self.__hash_utils_instance_respond_to? :cut!
400
+ def cut!(length)
401
+ delta = self.length - length
402
+
403
+ if delta >= 0
404
+ self.slice! delta..(self.length)
405
+ self
406
+ else
407
+ self.clear
408
+ end
409
+ end
410
+ end
411
+
412
+ ##
413
+ # Cuts out given portion of the array from the end and returns
414
+ # remaining.
415
+ #
416
+ # @example
417
+ # [1, 2, 3, 4, 5, 6].cut! 2 # will return [1, 2, 3, 4]
418
+ #
419
+ # @param [Integer] indexes indexes to cut out
420
+ # @return [Array] resultant array
421
+ # @since 2.1.0
422
+ #
423
+
424
+ if not self.__hash_utils_instance_respond_to? :cut
425
+ def cut(length)
426
+ self.dup.cut! length
427
+ end
428
+ end
429
+
430
+ ##
431
+ # Performs classical +#zip+ on array, but in place.
432
+ #
433
+ # @example
434
+ # arr = [1, 2, 3]
435
+ # arr.zip!
436
+ # arr == [1, 3, 4].zip # will be true
437
+ #
438
+ # @param *[Array] members
439
+ # @return [Array]
440
+ # @since 2.1.0
441
+ #
442
+
443
+ if not self.__hash_utils_instance_respond_to? :zip!
444
+ def zip!(*members)
445
+ self.map! { |i| [i] }
446
+ lengths = [ ]
447
+
448
+ # creates zip by hand
449
+ members.each_index do |i|
450
+ item = members[i]
451
+ lengths << item.length
452
+
453
+ item.each_index do |j|
454
+ self[j][i + 1] = item[j]
455
+ end
456
+ end
457
+
458
+ # padds to fixed length according to longest
459
+ if not lengths.empty?
460
+ padding = lengths.max + 1
461
+ self.each { |i| i.complete_to!(padding) }
462
+ end
463
+
464
+ return self
465
+ end
466
+ end
467
+
468
+ ##
469
+ # Completes array to given length using given member. Shortens
470
+ # longer arrays.
471
+ #
472
+ # @example
473
+ # [1, 2, 3].complete_to(5, :a) # will return [1, 2, 3, :a, :a]
474
+ #
475
+ # @param [Integer] length
476
+ # @param [Object] member
477
+ # @return [Array] resultant array
478
+ # @since 0.2.1
479
+ #
480
+
481
+ if not self.__hash_utils_instance_respond_to? :complete_to
482
+ def complete_to(length, member = nil)
483
+ self.dup.complete_to!(length, member)
484
+ end
485
+ end
486
+
487
+ ##
488
+ # Completes array to given length using given member in place.
489
+ # Shortens longer arrays.
490
+ #
491
+ # @example
492
+ # x = [1, 2, 3]
493
+ # x = x.complete_to!(5, :a) # will return [1, 2, 3, :a, :a]
494
+ #
495
+ # @param [Integer] length
496
+ # @param [Object] member
497
+ # @return [Array] itself
498
+ # @since 0.2.1
499
+ #
500
+
501
+ if not self.__hash_utils_instance_respond_to? :complete_to!
502
+ def complete_to!(length, member = nil)
503
+ delta = length - self.length
504
+
505
+ if delta > 0
506
+ fill = [member] * delta
507
+ self.push(*fill)
508
+ elsif delta == 0
509
+ self
510
+ else
511
+ self.shrink_to!(length)
512
+ end
513
+ end
514
+ end
515
+
516
+ ##
517
+ # Shrinks array to given length. Ignores shorten arrays.
518
+ #
519
+ # @example
520
+ # [1, 2, 3, 4, 5].shrink_to(3) # will return [1, 2, 3]
521
+ #
522
+ # @param [Integer] length
523
+ # @return [Array] shorten array
524
+ # @since 0.2.1
525
+ #
526
+
527
+ if not self.__hash_utils_instance_respond_to? :shrink_to
528
+ def shrink_to(length)
529
+ self.dup.shrink_to! length
530
+ end
531
+ end
532
+
533
+ ##
534
+ # Shrinks array to given length in place. Ignores shorten arrays.
535
+ #
536
+ # @example
537
+ # x = [1, 2, 3, 4, 5]
538
+ # x.shrink_to!(3) # will return [1, 2, 3]
539
+ #
540
+ # @param [Integer] length
541
+ # @return [Array] shorten array
542
+ # @since 0.2.1
543
+ #
544
+
545
+ if not self.__hash_utils_instance_respond_to? :shrink_to!
546
+ def shrink_to!(length)
547
+ delta = self.length - length
548
+
549
+ if length < 0
550
+ raise ::ArgumentError::new("negative argument")
551
+ elsif delta > 0
552
+ self.cut! self.length - length
553
+ else
554
+ self
555
+ end
556
+ end
557
+ end
558
+
559
+ ##
560
+ # Make +#drop+, but in-place.
561
+ #
562
+ # @example
563
+ # x = [1, 2, 3, 4, 5]
564
+ # x.drop! 3 # will return [4, 5] which will be in the variable
565
+ #
566
+ # @param [Integer] length
567
+ # @return [Array] remaining part
568
+ # @since 0.2.1
569
+ #
570
+
571
+ if not self.__hash_utils_instance_respond_to? :drop!
572
+ def drop!(length)
573
+ if length < 0
574
+ raise ArgumentError::new('attempt to drop negative size')
575
+ elsif length == 0
576
+ self
577
+ else
578
+ self.slice! 0..(length - 1)
579
+ self
580
+ end
581
+ end
582
+ end
583
+
310
584
  end
311
585