epitools 0.5.114 → 0.5.115
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 +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext.rb +1 -0
- data/lib/epitools/core_ext/misc.rb +0 -12
- data/lib/epitools/core_ext/numbers.rb +0 -42
- data/lib/epitools/core_ext/time.rb +56 -0
- data/lib/epitools/term.rb +36 -0
- data/spec/core_ext_spec.rb +15 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8eee5098324ab45b4dd6302f414fa5481774f478c6f6dd69839ed12670277a8
|
4
|
+
data.tar.gz: '0828b2ee573f259aedaa75398c2878bd489aaff40567ba71d2322ab6f3083ff2'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451de82760520fb395f34c9f88de6bc9c74f94576e256379390076f3f019453bed5457165a7371ecafa12103c3eae453d27533aee65662604f4562ff5ddc78e2
|
7
|
+
data.tar.gz: 68fdc3a7e6294f5fad2c79fc79c411feb565fed4386455a05bea879a57d21c32f92a6156b94befe45b89a73b90321aa989cd845337c80f26ec7d29a6b0b221d8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.115
|
data/lib/epitools/core_ext.rb
CHANGED
@@ -12,6 +12,7 @@ require 'epitools/core_ext/hash'
|
|
12
12
|
require 'epitools/core_ext/numbers'
|
13
13
|
require 'epitools/core_ext/truthiness'
|
14
14
|
require 'epitools/core_ext/range'
|
15
|
+
require 'epitools/core_ext/time'
|
15
16
|
require 'epitools/core_ext/misc'
|
16
17
|
|
17
18
|
##############################################################################
|
@@ -201,18 +201,6 @@ end
|
|
201
201
|
URI::RFC3986_Parser.prepend(Better_URI_RFC3986_Parser)
|
202
202
|
|
203
203
|
|
204
|
-
class Time
|
205
|
-
|
206
|
-
#
|
207
|
-
# Which "quarter" of the year does this date fall into?
|
208
|
-
#
|
209
|
-
def quarter
|
210
|
-
(month / 3.0).ceil
|
211
|
-
end
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
|
216
204
|
|
217
205
|
#
|
218
206
|
# Give ObjectSpace Enumerable powers (select, map, etc.)
|
@@ -411,48 +411,6 @@ class Float
|
|
411
411
|
end
|
412
412
|
|
413
413
|
|
414
|
-
class Time
|
415
|
-
|
416
|
-
#
|
417
|
-
# Relative time, in words. (eg: "1 second ago", "2 weeks from now", etc.)
|
418
|
-
#
|
419
|
-
def in_words
|
420
|
-
delta = (Time.now-self).to_i
|
421
|
-
a = delta.abs
|
422
|
-
|
423
|
-
amount = case a
|
424
|
-
when 0
|
425
|
-
'just now'
|
426
|
-
when 1
|
427
|
-
'1 second'
|
428
|
-
when 2..59
|
429
|
-
"second".amount(a)
|
430
|
-
when 1.minute...1.hour
|
431
|
-
"minute".amount(a/1.minute)
|
432
|
-
when 1.hour...1.day
|
433
|
-
"hour".amount(a/1.hour)
|
434
|
-
when 1.day...7.days
|
435
|
-
"day".amount(a/1.day)
|
436
|
-
when 1.week...1.month
|
437
|
-
"week".amount(a/1.week)
|
438
|
-
when 1.month...12.months
|
439
|
-
"month".amount(a/1.month)
|
440
|
-
else
|
441
|
-
"year".amount(a/1.year)
|
442
|
-
end
|
443
|
-
|
444
|
-
if delta < 0
|
445
|
-
amount += " from now"
|
446
|
-
elsif delta > 0
|
447
|
-
amount += " ago"
|
448
|
-
end
|
449
|
-
|
450
|
-
amount
|
451
|
-
end
|
452
|
-
|
453
|
-
end
|
454
|
-
|
455
|
-
|
456
414
|
class Prime
|
457
415
|
|
458
416
|
#
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Time
|
2
|
+
|
3
|
+
#
|
4
|
+
# Relative time, in words. (eg: "1 second ago", "2 weeks from now", etc.)
|
5
|
+
#
|
6
|
+
def in_words
|
7
|
+
delta = (Time.now-self).to_i
|
8
|
+
a = delta.abs
|
9
|
+
|
10
|
+
amount = case a
|
11
|
+
when 0
|
12
|
+
'just now'
|
13
|
+
when 1
|
14
|
+
'1 second'
|
15
|
+
when 2..59
|
16
|
+
"second".amount(a)
|
17
|
+
when 1.minute...1.hour
|
18
|
+
"minute".amount(a/1.minute)
|
19
|
+
when 1.hour...1.day
|
20
|
+
"hour".amount(a/1.hour)
|
21
|
+
when 1.day...7.days
|
22
|
+
"day".amount(a/1.day)
|
23
|
+
when 1.week...1.month
|
24
|
+
"week".amount(a/1.week)
|
25
|
+
when 1.month...12.months
|
26
|
+
"month".amount(a/1.month)
|
27
|
+
else
|
28
|
+
"year".amount(a/1.year)
|
29
|
+
end
|
30
|
+
|
31
|
+
if delta < 0
|
32
|
+
amount += " from now"
|
33
|
+
elsif delta > 0
|
34
|
+
amount += " ago"
|
35
|
+
end
|
36
|
+
|
37
|
+
amount
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Which "quarter" of the year does this date fall into?
|
42
|
+
#
|
43
|
+
def quarter
|
44
|
+
(month / 3.0).ceil
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# How many seconds have elapsed since this time?
|
49
|
+
#
|
50
|
+
def elapsed
|
51
|
+
Time.now - self
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
data/lib/epitools/term.rb
CHANGED
@@ -41,6 +41,42 @@ module Term
|
|
41
41
|
print "\e[H\e[J"
|
42
42
|
end
|
43
43
|
|
44
|
+
def clear_line
|
45
|
+
print "\e[2K"
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear_eol
|
49
|
+
print "\e[0K"
|
50
|
+
end
|
51
|
+
|
52
|
+
def move_to(row: 1, col: 1)
|
53
|
+
print "\e[#{row};#{col}H"
|
54
|
+
end
|
55
|
+
|
56
|
+
def home
|
57
|
+
move_to
|
58
|
+
end
|
59
|
+
|
60
|
+
def move_to_row(n)
|
61
|
+
move_to(row: n)
|
62
|
+
end
|
63
|
+
|
64
|
+
def move_to_bottom
|
65
|
+
move_to_row(height-1)
|
66
|
+
end
|
67
|
+
|
68
|
+
def move_to_top
|
69
|
+
move_to_row(1)
|
70
|
+
end
|
71
|
+
|
72
|
+
def hide_cursor
|
73
|
+
print "\e[?25l"
|
74
|
+
end
|
75
|
+
|
76
|
+
def show_cursor
|
77
|
+
print "\e[?25h"
|
78
|
+
end
|
79
|
+
|
44
80
|
def color(fore, back=nil)
|
45
81
|
@fore = fore
|
46
82
|
@back = back if back
|
data/spec/core_ext_spec.rb
CHANGED
@@ -98,25 +98,28 @@ describe Object do
|
|
98
98
|
|
99
99
|
it "memoizes" do
|
100
100
|
|
101
|
+
$sideffect = 0
|
102
|
+
|
101
103
|
class Fake
|
102
104
|
|
103
|
-
def
|
104
|
-
|
105
|
+
memoize def cached_value
|
106
|
+
$sideffect += 1
|
107
|
+
:value
|
105
108
|
end
|
106
|
-
memoize :cacheme
|
107
109
|
|
108
110
|
end
|
109
111
|
|
110
112
|
f = Fake.new
|
111
|
-
f.instance_variable_get("@cacheme").should == nil
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
f.
|
114
|
+
$sideffect.should == 0
|
115
|
+
|
116
|
+
f.cached_value.should == :value
|
117
|
+
$sideffect.should == 1
|
116
118
|
|
117
|
-
f.
|
118
|
-
|
119
|
-
|
119
|
+
f.cached_value.should == :value
|
120
|
+
$sideffect.should == 1
|
121
|
+
|
122
|
+
$sideffect = nil
|
120
123
|
end
|
121
124
|
|
122
125
|
end
|
@@ -170,6 +173,8 @@ describe Numeric do
|
|
170
173
|
5.days.ago.to_i.should == (Time.now - 5.days).to_i
|
171
174
|
1.year.ago.year.should == Time.now.year - 1
|
172
175
|
5.days.from_now.to_i.should == (Time.now + 5.days).to_i
|
176
|
+
|
177
|
+
1.day.ago.elapsed.should be_within(0.1).of(1.day)
|
173
178
|
end
|
174
179
|
|
175
180
|
it "thingses" do
|
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.115
|
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-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/epitools/core_ext/object.rb
|
63
63
|
- lib/epitools/core_ext/range.rb
|
64
64
|
- lib/epitools/core_ext/string.rb
|
65
|
+
- lib/epitools/core_ext/time.rb
|
65
66
|
- lib/epitools/core_ext/truthiness.rb
|
66
67
|
- lib/epitools/daemonize.rb
|
67
68
|
- lib/epitools/hexdump.rb
|