epitools 0.5.113 → 0.5.114
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/colored.rb +3 -0
- data/lib/epitools/core_ext/array.rb +1 -0
- data/lib/epitools/core_ext/enumerable.rb +4 -1
- data/lib/epitools/core_ext/hash.rb +14 -0
- data/lib/epitools/core_ext/misc.rb +34 -1
- data/lib/epitools/minimal.rb +7 -0
- data/lib/epitools/path.rb +3 -2
- data/spec/core_ext_spec.rb +28 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12639fe716d554565a2dafdf486f339a0b5a85389dd6ab751c05ccbfbd6d76c3
|
4
|
+
data.tar.gz: dc13d1ab805e37c082a14af7e4262a86d7aed06842147f1405c3cce028d0b3c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd51698c2b95781babd4b7b4b741d39eac594852c2695f011c483d962d7498d6a426287e2486e158d7ff4f70d1145b385cc113a4e2fd9479404934b3f4d95faf
|
7
|
+
data.tar.gz: 2a00245d9dc98adde9e5cdee8f565c7c1875f03b1413ff24a6e8de67546220f09d437440b54f4a480338cc9fadb5bd8fb7efbb694090ef4e862138ce0389b469
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.114
|
data/lib/epitools/colored.rb
CHANGED
@@ -39,6 +39,9 @@
|
|
39
39
|
# >> Colored.enable_temporarily { puts "whee!".red }
|
40
40
|
#
|
41
41
|
|
42
|
+
# ANSI spec:
|
43
|
+
# https://github.com/tonyg/racket-ansi/blob/master/doc/all-escapes.txt
|
44
|
+
|
42
45
|
require 'set'
|
43
46
|
require 'rbconfig'
|
44
47
|
require 'Win32/Console/ANSI' if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
@@ -240,10 +240,13 @@ module Enumerable
|
|
240
240
|
already_seen = Set.new
|
241
241
|
|
242
242
|
Enumerator::Lazy.new(self) do |yielder, value|
|
243
|
-
|
243
|
+
key = block_given? ? yield(value) : value
|
244
|
+
yielder << value if already_seen.add?(key)
|
244
245
|
end
|
245
246
|
end
|
246
247
|
|
248
|
+
alias_method :uniq_by, :uniq
|
249
|
+
|
247
250
|
#
|
248
251
|
# The same as "map", except that if an element is an Array or Enumerable, map is called
|
249
252
|
# recursively on that element. (Hashes are ignored because of the complications of block
|
@@ -1,6 +1,20 @@
|
|
1
1
|
|
2
2
|
class Hash
|
3
3
|
|
4
|
+
#
|
5
|
+
# `hash1 + hash2` merge the two hashes, returning a new hash
|
6
|
+
#
|
7
|
+
def +(other)
|
8
|
+
merge(other)
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# `hash1 - hash2` removes keys from hash1 that exist in hash2, returning a new hash
|
13
|
+
#
|
14
|
+
def -(other)
|
15
|
+
dup.delete_if { |k,v| other.includes?(k) }
|
16
|
+
end
|
17
|
+
|
4
18
|
#
|
5
19
|
# 'true' if the Hash has no entries
|
6
20
|
#
|
@@ -144,6 +144,39 @@ module URI
|
|
144
144
|
to_s
|
145
145
|
end
|
146
146
|
|
147
|
+
#
|
148
|
+
# Default user agent for the 'get' method
|
149
|
+
#
|
150
|
+
# USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
|
151
|
+
|
152
|
+
#
|
153
|
+
# Get this URI using Net::HTTP
|
154
|
+
#
|
155
|
+
def get(headers={}, redirect_limit=10)
|
156
|
+
raise "Sorry, URI can't get from #{scheme.inspect} URIs yet" unless scheme =~ /^https?$/
|
157
|
+
raise 'Too many HTTP redirections' if redirect_limit == 0
|
158
|
+
|
159
|
+
# headers['User-Agent'] ||= USER_AGENT
|
160
|
+
|
161
|
+
# response = Net::HTTP.start(host, port) do |http|
|
162
|
+
# # the_path = path.empty? ? "/" : path
|
163
|
+
# req = Net::HTTP::Get.new(self, headers)
|
164
|
+
# http.request(req)
|
165
|
+
# end
|
166
|
+
|
167
|
+
response = Net::HTTP.get_response(self)
|
168
|
+
|
169
|
+
case response
|
170
|
+
when Net::HTTPSuccess
|
171
|
+
response
|
172
|
+
when Net::HTTPRedirection
|
173
|
+
# puts "redirect: #{response['location']}"
|
174
|
+
URI(response['location']).get(headers, redirect_limit-1)
|
175
|
+
else
|
176
|
+
response.error!
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
147
180
|
end
|
148
181
|
|
149
182
|
#
|
@@ -156,7 +189,7 @@ module Better_URI_RFC3986_Parser # ::RFC3986_relative_ref
|
|
156
189
|
subsitutions = ESCAPE_ME_PLZ.chars.map { |c| [c, CGI.escape(c)] }
|
157
190
|
subsitutions << [" ", "%20"]
|
158
191
|
|
159
|
-
subsitutions.each do |find, replace|
|
192
|
+
subsitutions.each do |find, replace|
|
160
193
|
uri = uri.gsub(find, replace)
|
161
194
|
end
|
162
195
|
|
data/lib/epitools/minimal.rb
CHANGED
data/lib/epitools/path.rb
CHANGED
@@ -653,8 +653,9 @@ class Path
|
|
653
653
|
#
|
654
654
|
# All the lines in this file, chomped.
|
655
655
|
#
|
656
|
-
def each_line
|
657
|
-
|
656
|
+
def each_line
|
657
|
+
return to_enum(:each_line) unless block_given?
|
658
|
+
open { |io| io.each_line { |line| yield line.chomp } }
|
658
659
|
end
|
659
660
|
alias_method :each, :each_line
|
660
661
|
alias_method :lines, :each_line
|
data/spec/core_ext_spec.rb
CHANGED
@@ -300,7 +300,7 @@ describe String do
|
|
300
300
|
it "wordses" do
|
301
301
|
s = "This, is a bunch, of words."
|
302
302
|
s.words.should == ["This", "is", "a", "bunch", "of", "words"]
|
303
|
-
|
303
|
+
|
304
304
|
"Weird word-like things".words.should == ["Weird", "word", "like", "things"]
|
305
305
|
end
|
306
306
|
|
@@ -664,6 +664,11 @@ describe Enumerable do
|
|
664
664
|
|
665
665
|
it "uniqs lazily" do
|
666
666
|
[0,0,0,1].cycle.uniq.take(2).to_a.should == [0,1]
|
667
|
+
[0,0,0,1].cycle.uniq_by(&:prime?).take(1).to_a.should == [0]
|
668
|
+
end
|
669
|
+
|
670
|
+
it "uniq_bys" do
|
671
|
+
[1,2,3,4].uniq_by(&:prime?).to_a.should == [1,2]
|
667
672
|
end
|
668
673
|
|
669
674
|
it "foldl's" do
|
@@ -1140,3 +1145,25 @@ describe "Anything" do
|
|
1140
1145
|
end
|
1141
1146
|
|
1142
1147
|
end
|
1148
|
+
|
1149
|
+
|
1150
|
+
describe URI do
|
1151
|
+
|
1152
|
+
it "paramses" do
|
1153
|
+
opts = {"q" => "hello", "p" => "whee"}
|
1154
|
+
query = opts.to_query
|
1155
|
+
query.should == "q=hello&p=whee"
|
1156
|
+
|
1157
|
+
uri = URI("http://blah.com/stuff?#{query}")
|
1158
|
+
|
1159
|
+
uri.params.should == opts
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
it "gets" do
|
1163
|
+
response = URI("http://google.com/").get
|
1164
|
+
response.body.size
|
1165
|
+
(response.size > 0).should == true
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
end
|
1169
|
+
|
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.
|
4
|
+
version: 0.5.114
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|