epitools 0.5.130 → 0.5.131

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
  SHA256:
3
- metadata.gz: d5b52f237d17762dca9dfa53fa0cbdae372f867f84fb455ca97656a9863d6763
4
- data.tar.gz: 25f2741a4a12dc257ef1d540dcbfea1e6fa7945267de324e1ddba4e860d44334
3
+ metadata.gz: 467e7148825ac612d6b8acc25da6c09e89521d734c38f64568b189f4c7df8b6e
4
+ data.tar.gz: 3319cb92d01f19e597cc00c4b30eb0b847e652e2fa53f8e63a96fff2dc6f2bc5
5
5
  SHA512:
6
- metadata.gz: 264e9ab8322afd8b6e08b3445dde07c4bf214a9da6e0b087e2c1117a5f0366edd5db361afd64a91faa24988618cf6fccf940ab7bfa7e76b63d8d53a905ef32ae
7
- data.tar.gz: 0bb9e187d248d149e60c05fbf7a5757a79d560e1452a6ccf808294fc0cb0816d6e9de53d997e2fdeba49056c09a0d55bb8de6b06332174bcdfafe2c6fc004fbb
6
+ metadata.gz: 518b4e0a4014fa2a0dbdeed3d2a3656887035526398062c29acfaf62b3acaf8a3fba81b55a15dc33efdc77818d359bf63c2dcb1cc1ecec0f14772052fadb25a2
7
+ data.tar.gz: f888b96dd3f917eb45977567bcd66b1a9972bae7ccaf3a8d82902964b7af569e1474dccbaade2379fa2ebb6e4073b74114e1c6b548a826481e6462de6979607a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.130
1
+ 0.5.131
@@ -253,6 +253,14 @@ class Numeric
253
253
  (self - 32) * 5.0 / 9.0
254
254
  end
255
255
 
256
+ def to_lbs
257
+ self / 0.45359237
258
+ end
259
+
260
+ def to_kg
261
+ self * 0.45359237
262
+ end
263
+
256
264
  end
257
265
 
258
266
 
@@ -9,6 +9,14 @@ class URI::Generic
9
9
  params.to_query
10
10
  end
11
11
 
12
+ #
13
+ # Set the query string
14
+ #
15
+ def query=(new_query)
16
+ @params = new_query.to_params
17
+ @query = new_query
18
+ end
19
+
12
20
  #
13
21
  # Return a Hash of the variables in the query string
14
22
  #
@@ -26,11 +26,12 @@
26
26
  # end
27
27
  #
28
28
  class JobRunner
29
- def initialize(*blocks)
29
+ def initialize(*blocks, debug: false)
30
30
  @threads = []
31
31
  @results = Thread::Queue.new
32
32
  @jobs = []
33
33
  @started = false
34
+ @debug = debug
34
35
 
35
36
  if blocks.any?
36
37
  blocks.each { |block| add &block }
@@ -39,20 +40,37 @@ class JobRunner
39
40
  end
40
41
  end
41
42
 
43
+ def dmsg(msg)
44
+ puts "[#{Time.now}] #{msg}" if @debug
45
+ end
46
+
42
47
  def add(&block)
48
+ dmsg("added job #{block}")
43
49
  @jobs << block
44
50
  end
45
51
 
46
52
  def reap!
47
- @threads.delete_if { |t| not t.alive? } if @threads.any?
53
+ if @threads.any?
54
+ dmsg("reaping #{@threads.size} threads")
55
+ @threads.delete_if { |t| not t.alive? }
56
+ else
57
+ dmsg("reap failed: no threads")
58
+ end
48
59
  end
49
60
 
50
61
  def go!
51
- raise "Error: already started" if @started
62
+ if @started
63
+ raise "Error: already started"
64
+ else
65
+ dmsg("starting #{@threads.size} jobs")
66
+ end
67
+
52
68
  @started = true
53
69
  @jobs.each do |job|
70
+ dmsg("adding #{job}")
54
71
  @threads << Thread.new do
55
72
  @results << job.call
73
+ dmsg("job #{job} complete")
56
74
  end
57
75
  end
58
76
  end
@@ -72,7 +90,7 @@ end
72
90
 
73
91
 
74
92
  if __FILE__ == $0
75
- JobRunner.new do |jr|
93
+ JobRunner.new(debug: true) do |jr|
76
94
  jr.add { 3 }
77
95
  jr.add { sleep 0.1; 2 }
78
96
  jr.add { sleep 0.2; 1 }
@@ -119,11 +119,20 @@ class Path
119
119
  # The file extension, including the . (eg: ".mp3")
120
120
  attr_reader :ext
121
121
 
122
+ URI_RE = %r{^[a-z\-]+://}i
122
123
 
123
124
  ###############################################################################
124
125
  # Initializers
125
126
  ###############################################################################
126
127
 
128
+ def self.new(*args)
129
+ if args.first =~ URI_RE and self != Path::URI
130
+ Path::URI.new(args.first)
131
+ else
132
+ super(*args)
133
+ end
134
+ end
135
+
127
136
  def initialize(newpath, hints={})
128
137
  send("path=", newpath, hints)
129
138
 
@@ -156,8 +165,8 @@ class Path
156
165
  path
157
166
  when String
158
167
 
159
- if path =~ %r{^[a-z\-]+://}i # URL?
160
- Path::URI.new(path)
168
+ if path =~ URI_RE
169
+ Path.new(path)
161
170
 
162
171
  else
163
172
  # TODO: highlight backgrounds of codeblocks to show indent level & put boxes (or rules?) around (between?) double-spaced regions
@@ -186,7 +195,7 @@ class Path
186
195
  # Note: The `hints` parameter contains options so `path=` doesn't have to touch the filesytem as much.
187
196
  #
188
197
  def path=(newpath, hints={})
189
- if hints[:type] or File.exists? newpath
198
+ if hints[:type] or File.exist? newpath
190
199
  if hints[:type] == :dir or File.directory? newpath
191
200
  self.dir = newpath
192
201
  else
@@ -357,7 +366,7 @@ class Path
357
366
  ###############################################################################
358
367
 
359
368
  def exists?
360
- File.exists? path
369
+ File.exist? path
361
370
  end
362
371
 
363
372
  def size
@@ -430,7 +439,7 @@ class Path
430
439
  end
431
440
 
432
441
  def broken_symlink?
433
- File.symlink?(path) and not File.exists?(path)
442
+ File.symlink?(path) and not File.exist?(path)
434
443
  end
435
444
 
436
445
  def symlink_target
@@ -1638,9 +1647,9 @@ class Path::URI < Path
1638
1647
  #
1639
1648
  # When this is: http://host.com:port/path/filename.ext?param1=value1&param2=value2&...
1640
1649
  #
1641
- def to_s
1642
- uri.to_s
1643
- end
1650
+ def to_s; uri.to_s; end
1651
+ def to_path; to_s; end
1652
+ def to_str; to_s; end
1644
1653
 
1645
1654
  def inspect
1646
1655
  "#<Path::URI:#{to_s}>"
@@ -1693,9 +1702,9 @@ class Path::URI < Path
1693
1702
  def open(mode="r", &block)
1694
1703
  require 'open-uri'
1695
1704
  if block_given?
1696
- Kernel.open(to_s, mode, &block)
1705
+ ::URI.open(to_s, mode, &block)
1697
1706
  else
1698
- Kernel.open(to_s, mode)
1707
+ ::URI.open(to_s, mode)
1699
1708
  end
1700
1709
  end
1701
1710
 
@@ -1296,11 +1296,11 @@ describe URI do
1296
1296
  uri.params.should == opts
1297
1297
  end
1298
1298
 
1299
- it "gets" do
1300
- response = URI("http://google.com/").get
1301
- response.body.size
1302
- (response.size > 0).should == true
1303
- end
1299
+ # it "gets" do
1300
+ # response = URI("http://google.com/").get
1301
+ # response.body.size
1302
+ # (response.size > 0).should == true
1303
+ # end
1304
1304
 
1305
1305
  it "params=" do
1306
1306
  u = "http://butt.cx/?q=1".to_uri
@@ -1310,6 +1310,10 @@ describe URI do
1310
1310
  u.params["q"].should == 2
1311
1311
  u.params.should == {"q" => 2}
1312
1312
  u.query.should == "q=2"
1313
+
1314
+ subbed = u.with(query: u.params.reject{|k,v| u.params.keys.include? 'q' }.to_query)
1315
+ subbed.params.should == {}
1316
+ subbed.query.should == ""
1313
1317
  end
1314
1318
 
1315
1319
  end
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.130
4
+ version: 0.5.131
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec