epitools 0.5.79 → 0.5.81

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35f295e371fac93821a798d357e66515f65d395e
4
- data.tar.gz: 9b523f2aff407af1512c10f38021d6208d6382c3
3
+ metadata.gz: 8331753ad7012fb296bd72ac0e18d68b670b69d2
4
+ data.tar.gz: 4fc4a3aae6820feb16508a0bf719e279c3865e2a
5
5
  SHA512:
6
- metadata.gz: ef520fc344b40d458b120cd9d9808cbb784c5d3afa864c266f4e881dec7a5b03b4ed5061a67a8655aed925183ac3237f8c60681bb0b88fb62b7eae9f15c17f7c
7
- data.tar.gz: 14d957b9c92aa215296dfe3dc04ed5cb076f9ceff9991840d4f81fdc85075cc75ee7465b1b42ffbdc402937c196847addaef55fed3e31f3862ca093da1c889f6
6
+ metadata.gz: 2169dc5158cd619f98e42f908a3cf4d1665ae9d5d38235e5b660fef4052d7e6a56359a7cdf7acfdb2122da630dfb3d30fdadbdd177db5eeaccff3966b330d5f6
7
+ data.tar.gz: 8a177e9b1d3f2dc232c9edc5874ce9801adb68d3f75ea6508a465ef7c1cdd2ba421edd2cf83c235cabc2adaedb4f66946dad3a1766f494e5a4f7ebc9e164c831
data/.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  "README.rdoc",
14
14
  "TODO"
15
15
  ]
16
- s.files = `git ls`.lines.map(&:strip)
16
+ s.files = `git ls-files`.lines.map(&:strip)
17
17
  s.homepage = "http://github.com/epitron/epitools"
18
18
  s.licenses = ["WTFPL"]
19
19
  s.require_paths = ["lib"]
data/Rakefile CHANGED
@@ -15,3 +15,15 @@ end
15
15
  task :pry do
16
16
  system "pry --gem"
17
17
  end
18
+
19
+ task :spec do
20
+ cmd = %w[rspec -fd -c spec]
21
+
22
+ if system *%w[which rescue]
23
+ system *(["rescue"]+cmd)
24
+ else
25
+ system *cmd
26
+ end
27
+ end
28
+
29
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.79
1
+ 0.5.81
@@ -27,22 +27,32 @@ module Digest
27
27
  autoload :MD5, 'digest/md5'
28
28
  end
29
29
 
30
- # Network Sockets
30
+ if RUBY_VERSION["1.8.7"]
31
+ autoload :Prime, 'mathn'
32
+ else
33
+ autoload :Prime, 'prime'
34
+ end
35
+
36
+
37
+ ## Networking
38
+
31
39
  ['IP', 'Basic', 'TCP', 'UDP', 'UNIX', ''].each do |type|
32
40
  autoload :"#{type}Socket", 'socket'
33
41
  end
34
42
 
35
- # Network Servers
36
43
  ['TCP', 'UNIX'].each do |type|
37
44
  autoload :"#{type}Server", 'socket'
38
45
  end
39
46
 
40
- if RUBY_VERSION["1.8.7"]
41
- autoload :Prime, 'mathn'
42
- else
43
- autoload :Prime, 'prime'
47
+ module Net
48
+ autoload :HTTP, 'net/http'
49
+ autoload :HTTPS, 'net/https'
50
+ autoload :FTP, 'net/ftp'
51
+ autoload :FTP, 'net/ftp'
44
52
  end
45
53
 
54
+ autoload :Resolv, 'resolv'
55
+
46
56
 
47
57
  ## Nonstandard library (epitools)
48
58
 
@@ -80,7 +90,8 @@ autoreq :AwesomePrint do
80
90
  end
81
91
  end
82
92
 
83
- ## YAML hacks (sometimes the module is loaded improperly)
93
+
94
+ ## YAML hacks (the module might not be loaded properly in older Rubies)
84
95
 
85
96
  if defined? YAML and not defined? YAML.parse
86
97
  del YAML # remove the existing module
@@ -59,6 +59,9 @@ module Enumerable
59
59
  # [1,2,3,4,5].split{ |e| e == 3 }
60
60
  # #=> [ [1,2], [4,5] ]
61
61
  #
62
+ # "hello\n\nthere\n".each_line.split_at("\n").to_a
63
+ # #=> [ ["hello\n"], ["there\n"] ]
64
+ #
62
65
  # [1,2,3,4,5].split(:include_boundary=>true) { |e| e == 3 }
63
66
  # #=> [ [1,2], [3,4,5] ]
64
67
  #
@@ -71,11 +74,10 @@ module Enumerable
71
74
  if matcher.nil?
72
75
  boundary_test_proc = block
73
76
  else
74
- if matcher.is_a? String or matcher.is_a? Regexp
75
- boundary_test_proc = proc { |element| element[matcher] rescue nil }
77
+ if matcher.is_a? Regexp
78
+ boundary_test_proc = proc { |element| element =~ matcher }
76
79
  else
77
80
  boundary_test_proc = proc { |element| element == matcher }
78
- #raise "I don't know how to split with #{matcher}"
79
81
  end
80
82
  end
81
83
 
@@ -191,6 +193,19 @@ module Enumerable
191
193
  sum / count.to_f
192
194
  end
193
195
 
196
+ #
197
+ # Lazily enumerate unique elements
198
+ # (WARNING: This can cause an infinite loop if you enumerate over a cycle,
199
+ # since it will keep reading the input until it finds a unique element)
200
+ #
201
+ def uniq
202
+ already_seen = Set.new
203
+
204
+ Enumerator::Lazy.new(self) do |yielder, value|
205
+ yielder << value if already_seen.add?(value)
206
+ end
207
+ end
208
+
194
209
  #
195
210
  # The same as "map", except that if an element is an Array or Enumerable, map is called
196
211
  # recursively on that element. (Hashes are ignored because of the complications of block
@@ -3,10 +3,6 @@ Number = Numeric # "obj.is_a? Number" just sounds better.
3
3
 
4
4
  class Numeric
5
5
 
6
- def integer?; true; end
7
-
8
- def truthy?; self > 0; end
9
-
10
6
  #
11
7
  # Convert this number to a string, adding commas between each group of 3 digits.
12
8
  #
@@ -251,11 +247,6 @@ end
251
247
 
252
248
 
253
249
  class Integer
254
-
255
- #
256
- # 'true' if the integer is 0
257
- #
258
- def blank?; self == 0; end
259
250
 
260
251
  #
261
252
  # Convert the number into a hexadecimal string representation.
@@ -376,6 +367,7 @@ end
376
367
  end
377
368
  end
378
369
 
370
+
379
371
  class Time
380
372
 
381
373
  #
@@ -2,40 +2,6 @@ require 'epitools/minimal'
2
2
  require 'epitools/core_ext/numbers'
3
3
 
4
4
  class String
5
-
6
- #
7
- # Could this string be cast to an integer?
8
- #
9
- def integer?
10
- strip.match(/^\d+$/) ? true : false
11
- end
12
-
13
- #
14
- # 'true' if the string's length is 0 (after whitespace has been stripped from the ends)
15
- #
16
- def blank?
17
- strip.size == 0
18
- end
19
-
20
- #
21
- # Is there anything in the string? (ignoring whitespace/newlines)
22
- #
23
- def any?
24
- not blank?
25
- end
26
- alias_method :present?, :any?
27
-
28
- #
29
- # Does this string contain something that means roughly "true"?
30
- #
31
- def truthy?
32
- case strip.downcase
33
- when "1", "true", "yes", "on", "enabled", "affirmative"
34
- true
35
- else
36
- false
37
- end
38
- end
39
5
 
40
6
  #
41
7
  # Convert \r\n to \n
@@ -6,6 +6,16 @@ class Object
6
6
  #
7
7
  def integer?; false; end
8
8
 
9
+ #
10
+ # Default "float?" behaviour.
11
+ #
12
+ def float?; false; end
13
+
14
+ #
15
+ # Default "number?" behaviour.
16
+ #
17
+ def number?; false; end
18
+
9
19
  #
10
20
  # `truthy?` means `not blank?`
11
21
  #
@@ -34,6 +44,27 @@ class FalseClass
34
44
  end
35
45
 
36
46
 
47
+ class Numeric
48
+
49
+ def truthy?; self > 0; end
50
+
51
+ def number?; true; end
52
+
53
+ end
54
+
55
+
56
+ class Integer
57
+
58
+ #
59
+ # 'true' if the integer is 0
60
+ #
61
+ def blank?; self == 0; end
62
+
63
+ def integer?; true; end
64
+
65
+ end
66
+
67
+
37
68
  class Float
38
69
 
39
70
  #
@@ -41,6 +72,8 @@ class Float
41
72
  #
42
73
  def blank?; self == 0.0; end
43
74
 
75
+ def float?; true; end
76
+
44
77
  end
45
78
 
46
79
 
@@ -62,3 +95,56 @@ class Symbol
62
95
  def blank?; false; end
63
96
 
64
97
  end
98
+
99
+
100
+ class String
101
+
102
+ #
103
+ # Could this string be cast to an integer?
104
+ #
105
+ def integer?
106
+ !!strip.match(/^-?\d+$/)
107
+ end
108
+
109
+ #
110
+ # Could this string be cast to an float?
111
+ #
112
+ def float?
113
+ !!strip.match(/^-?\d+\.\d+$/)
114
+ end
115
+
116
+ #
117
+ # Could this string be cast to an number?
118
+ #
119
+ def number?
120
+ !!strip.match(/^-?\d\.?\d*$/)
121
+ end
122
+
123
+ #
124
+ # 'true' if the string's length is 0 (after whitespace has been stripped from the ends)
125
+ #
126
+ def blank?
127
+ strip.size == 0
128
+ end
129
+
130
+ #
131
+ # Is there anything in the string? (ignoring whitespace/newlines)
132
+ #
133
+ def any?
134
+ not blank?
135
+ end
136
+ alias_method :present?, :any?
137
+
138
+ #
139
+ # Does this string contain something that means roughly "true"?
140
+ #
141
+ def truthy?
142
+ case strip.downcase
143
+ when "1", "true", "yes", "on", "enabled", "affirmative"
144
+ true
145
+ else
146
+ false
147
+ end
148
+ end
149
+
150
+ end
@@ -1,3 +1,9 @@
1
+ #
2
+ # If you require 'epitools/minimal' instead of 'epitools',
3
+ # this is what you get: core_ext monkeypatches and all the
4
+ # autoloads; the barest essentials for survival.
5
+ #
6
+
1
7
  if RUBY_VERSION[/^1.8/]
2
8
  require 'enumerator'
3
9
  Enumerator = Enumerable::Enumerator unless defined? Enumerator
@@ -251,7 +251,6 @@ describe String do
251
251
  " asdf" => " Asdf",
252
252
  "ASDFASDFA SDF" => "Asdfasdfa Sdf",
253
253
  "What's Up" => "What's Up",
254
- "What's Up" => "What's Up",
255
254
  "they're awesome" => "They're Awesome",
256
255
  "king of pain" => "King of Pain",
257
256
  "a-b-c 1-2-3" => "A-B-C 1-2-3",
@@ -342,11 +341,11 @@ end
342
341
 
343
342
  describe Integer do
344
343
 
345
- it "integer?" do
344
+ it "integer?s" do
346
345
 
347
346
  {
348
- true => [ "123", "000", 123, 123.45 ],
349
- false => [ "123asdf", "asdfasdf", Object.new, nil ]
347
+ true => [ "123", "000", 123 ],
348
+ false => [ "123asdf", "asdfasdf", Object.new, nil, 123.45 ]
350
349
  }.each do |expected_result, objects|
351
350
  objects.each { |object| object.integer?.should == expected_result }
352
351
  end
@@ -401,6 +400,30 @@ describe Integer do
401
400
 
402
401
  end
403
402
 
403
+ describe Float do
404
+
405
+ it "float?" do
406
+ {
407
+ true => [ "0.0", "1.000", 123.45 ],
408
+ false => [ "123asdf", "asdfasdf", Object.new, nil, 12345, "000", "123" ]
409
+ }.each do |expected_result, objects|
410
+ objects.each { |object| object.float?.should == expected_result }
411
+ end
412
+ end
413
+ end
414
+
415
+ describe Number do
416
+
417
+ it "number?" do
418
+ {
419
+ true => [ "0.0", " 1.0", "1.000", "-1", "-1.25", 123.45, 12345, "000", "123", "1" ],
420
+ false => [ "123asdf", "abcd123", "asdfasdf", Object.new, nil ]
421
+ }.each do |expected_result, objects|
422
+ objects.each { |object| object.number?.should == expected_result }
423
+ end
424
+ end
425
+
426
+ end
404
427
 
405
428
  describe Array do
406
429
 
@@ -477,8 +500,11 @@ describe Enumerable do
477
500
  [1,2,3,4,5].split_after {|e| e == 3}.should == [ [1,2,3], [4,5] ]
478
501
  [1,2,3,4,5].split_before {|e| e == 3}.should == [ [1,2], [3,4,5] ]
479
502
 
480
- result = "a\nb\n---\nc\nd\n".lines.split_at(/---/)
481
- result.map_recursively(&:strip).should == [ %w[a b], %w[c d] ]
503
+ result = "a\nb\n---\nc\nd\n".each_line.split_at(/---/)
504
+ result.to_a.should == [ ["a\n", "b\n"], ["c\n", "d\n"] ]
505
+
506
+ result = "hello\n\nthere\n".each_line.split_at("\n")
507
+ result.to_a.should == [ ["hello\n"], ["there\n"] ]
482
508
  end
483
509
 
484
510
  it "splits with nested things" do
@@ -534,6 +560,10 @@ describe Enumerable do
534
560
  [1,1,3,3].average.should == 2.0
535
561
  end
536
562
 
563
+ it "uniqs lazily" do
564
+ [0,0,0,1].cycle.uniq.take(2).to_a.should == [0,1]
565
+ end
566
+
537
567
  it "foldl's" do
538
568
  a = [1,2,3,4]
539
569
  a.foldl(:+).should == a.sum
@@ -764,6 +794,7 @@ describe BasicObject do
764
794
 
765
795
  end
766
796
 
797
+
767
798
  describe Range do
768
799
 
769
800
  it "generates random numbers" do
@@ -780,6 +811,7 @@ describe Range do
780
811
 
781
812
  end
782
813
 
814
+
783
815
  describe ObjectSpace do
784
816
 
785
817
  it "is Enumerable" do
@@ -788,6 +820,7 @@ describe ObjectSpace do
788
820
 
789
821
  end
790
822
 
823
+
791
824
  describe Matrix do
792
825
 
793
826
  it "draws a matrix" do
@@ -822,19 +855,23 @@ describe Matrix do
822
855
 
823
856
  end
824
857
 
858
+
825
859
  describe "truthiness" do
826
860
 
827
861
  it "is truthy!" do
828
862
  {
829
863
  # truthy things
830
864
  true => [
831
- "yes", "on", "1", "Enabled", 1, 1.7, :blah, true, [1,2,3], [1,2,3].to_enum,
865
+ "yes", "on", "1", "Enabled",
866
+ 1, 1.7,
867
+ :blah, true,
868
+ [1,2,3], [1,2,3].to_enum,
832
869
  1938389127239847129803741980237498012374,
833
870
  ],
834
871
 
835
872
  # untruthy things
836
873
  false => [
837
- "", " ", "asdf", 0, 0.0, false, nil, [], [].to_enum,
874
+ "", " ", "\t\n ", "asdf", 0, 0.0, false, nil, [], [].to_enum,
838
875
  ]
839
876
  }.each do |truthiness, objs|
840
877
  objs.each { |obj| obj.truthy?.should == truthiness }
@@ -843,6 +880,7 @@ describe "truthiness" do
843
880
 
844
881
  end
845
882
 
883
+
846
884
  describe "proper grammar" do
847
885
 
848
886
  it "responds_to?" do
@@ -885,6 +923,7 @@ describe "global methods" do
885
923
 
886
924
  end
887
925
 
926
+
888
927
  describe "to_jsons and to_yamls" do
889
928
  data = {"a"=>"b", "yes"=>true, "hello"=>[1,2,3,4,5]}
890
929
  data.to_json.from_json.should == data
@@ -893,6 +932,7 @@ describe "to_jsons and to_yamls" do
893
932
  data.to_yaml.from_yaml.should == data
894
933
  end
895
934
 
935
+
896
936
  describe "to_hms and from_hms" do
897
937
  60.to_hms.should == "01:00"
898
938
  60.to_hms.from_hms.should == 60
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.79
4
+ version: 0.5.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.4.5
126
+ rubygems_version: 2.4.5.1
127
127
  signing_key:
128
128
  specification_version: 3
129
129
  summary: Not utils... METILS!