epitools 0.5.133 → 0.5.136
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/Rakefile +5 -7
- data/VERSION +1 -1
- data/lib/epitools/autoloads.rb +5 -2
- data/lib/epitools/browser/cache.rb +1 -1
- data/lib/epitools/browser.rb +4 -4
- data/lib/epitools/clitools.rb +21 -4
- data/lib/epitools/core_ext/array.rb +1 -1
- data/lib/epitools/core_ext/numbers.rb +34 -3
- data/lib/epitools/core_ext/object.rb +4 -1
- data/lib/epitools/core_ext/string.rb +99 -3
- data/lib/epitools/fraction.rb +131 -0
- data/lib/epitools/gem_ext/oga.rb +31 -0
- data/lib/epitools/hexdump.rb +1 -1
- data/lib/epitools/minimal.rb +2 -3
- data/lib/epitools/path.rb +34 -19
- data/lib/epitools/pretty_backtrace.rb +1 -1
- data/lib/epitools/rash.rb +1 -1
- data/lib/epitools/term.rb +73 -15
- data/spec/core_ext_spec.rb +26 -2
- data/spec/fraction_spec.rb +53 -0
- data/spec/numwords_spec.rb +2 -5
- data/spec/path_spec.rb +14 -4
- data/spec/sys_spec.rb +5 -0
- data/spec/zopen_spec.rb +37 -37
- metadata +8 -6
- data/lib/epitools/ratio.rb +0 -78
- /data/spec/{browser_spec.rb → manual/browser_spec.rb} +0 -0
- /data/spec/{wm_spec.rb → manual/wm_spec.rb} +0 -0
data/lib/epitools/path.rb
CHANGED
@@ -125,16 +125,17 @@ class Path
|
|
125
125
|
# Initializers
|
126
126
|
###############################################################################
|
127
127
|
|
128
|
+
alias_class_method :old_new, :new
|
128
129
|
def self.new(*args)
|
129
130
|
if args.first =~ URI_RE and self != Path::URI
|
130
131
|
Path::URI.new(args.first)
|
131
132
|
else
|
132
|
-
|
133
|
+
old_new(*args)
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
136
|
-
def initialize(newpath, hints
|
137
|
-
send("path=", newpath, hints)
|
137
|
+
def initialize(newpath, **hints)
|
138
|
+
send("path=", newpath, **hints)
|
138
139
|
|
139
140
|
# if hints[:unlink_when_garbage_collected]
|
140
141
|
# backup_path = path.dup
|
@@ -155,8 +156,8 @@ class Path
|
|
155
156
|
Shellwords.escape(str)
|
156
157
|
end
|
157
158
|
|
158
|
-
def self.glob(str, hints
|
159
|
-
Dir[str].map { |entry| new(entry, hints) }
|
159
|
+
def self.glob(str, **hints)
|
160
|
+
Dir[str].map { |entry| new(entry, **hints) }
|
160
161
|
end
|
161
162
|
|
162
163
|
def self.[](path)
|
@@ -194,7 +195,7 @@ class Path
|
|
194
195
|
#
|
195
196
|
# Note: The `hints` parameter contains options so `path=` doesn't have to touch the filesytem as much.
|
196
197
|
#
|
197
|
-
def path=(newpath, hints
|
198
|
+
def path=(newpath, **hints)
|
198
199
|
if hints[:type] or File.exist? newpath
|
199
200
|
if hints[:type] == :dir or File.directory? newpath
|
200
201
|
self.dir = newpath
|
@@ -816,7 +817,7 @@ class Path
|
|
816
817
|
# zopen("otherfile.gz", "w") #=> #<Zlib::GzipWriter:0x7fe30448>>
|
817
818
|
# zopen("test.txt.gz") { |f| f.read } # read the contents of the .gz file, then close the file handle automatically.
|
818
819
|
#
|
819
|
-
def zopen(mode="rb", &block)
|
820
|
+
def zopen(mode="rb", **opts, &block)
|
820
821
|
# if ext == "gz"
|
821
822
|
# io = open(mode)
|
822
823
|
# case mode
|
@@ -829,7 +830,7 @@ class Path
|
|
829
830
|
# raise "Unknown mode: #{mode.inspect}. zopen only supports 'r' and 'w'."
|
830
831
|
# end
|
831
832
|
# elsif bin = COMPRESSORS[ext]
|
832
|
-
if bin = COMPRESSORS[ext]
|
833
|
+
if bin = (opts[:format] || COMPRESSORS[ext])
|
833
834
|
if which(bin)
|
834
835
|
case mode
|
835
836
|
when "w", "wb"
|
@@ -868,18 +869,25 @@ class Path
|
|
868
869
|
|
869
870
|
end
|
870
871
|
|
872
|
+
def self.zopen(filename, mode, &block)
|
873
|
+
Path.new(filename).zopen(mode, &block)
|
874
|
+
end
|
875
|
+
|
871
876
|
###############################################################################
|
872
877
|
# Parsing files
|
873
878
|
###############################################################################
|
874
879
|
|
875
880
|
#
|
876
881
|
# Parse the file based on the file extension.
|
877
|
-
# (Handles json, html, yaml, xml, csv, marshal, and bson.)
|
882
|
+
# (Handles json, html, yaml, xml, csv, tsv, marshal, and bson.)
|
883
|
+
#
|
884
|
+
# The "format" option lets you specify the file format (eg: `Path["something.conf"].parse(format: "yaml")`)
|
885
|
+
# You can also pass CSV parsing options (eg: `Path["thing.csv"].parse(col_sep: "\t")`)
|
878
886
|
#
|
879
|
-
def parse(io=self.io,
|
880
|
-
case (
|
887
|
+
def parse(io=self.io, **opts)
|
888
|
+
case (opts[:format] || ext.downcase)
|
881
889
|
when 'gz', 'bz2', 'xz'
|
882
|
-
parse(zopen, exts[-2])
|
890
|
+
parse(zopen, format: exts[-2])
|
883
891
|
when 'json'
|
884
892
|
read_json(io)
|
885
893
|
when 'html', 'htm'
|
@@ -889,7 +897,10 @@ class Path
|
|
889
897
|
when 'xml', 'rdf', 'rss'
|
890
898
|
read_xml(io)
|
891
899
|
when 'csv'
|
892
|
-
read_csv(io, opts)
|
900
|
+
read_csv(io, **opts)
|
901
|
+
when 'tsv'
|
902
|
+
opts[:col_sep] ||= "\t"
|
903
|
+
read_csv(io, **opts)
|
893
904
|
when 'marshal'
|
894
905
|
read_marshal(io)
|
895
906
|
when 'bson'
|
@@ -920,7 +931,8 @@ class Path
|
|
920
931
|
|
921
932
|
|
922
933
|
def read_html(io=self.io)
|
923
|
-
Nokogiri::HTML(io)
|
934
|
+
#Nokogiri::HTML(io)
|
935
|
+
Oga.parse_html(io)
|
924
936
|
end
|
925
937
|
alias_method :from_html, :read_html
|
926
938
|
|
@@ -938,14 +950,15 @@ class Path
|
|
938
950
|
|
939
951
|
|
940
952
|
# Parse the file as CSV
|
941
|
-
def read_csv(io=self.io, opts
|
942
|
-
|
953
|
+
def read_csv(io=self.io, **opts)
|
954
|
+
CSV.new(io.read, **opts).each
|
943
955
|
end
|
944
956
|
alias_method :from_csv, :read_csv
|
945
957
|
|
946
958
|
# Parse the file as XML
|
947
959
|
def read_xml(io=self.io)
|
948
|
-
Nokogiri::XML(io)
|
960
|
+
# Nokogiri::XML(io)
|
961
|
+
Oga.parse_xml(io)
|
949
962
|
end
|
950
963
|
|
951
964
|
# Parse the file as a Ruby Marshal dump
|
@@ -1024,6 +1037,7 @@ class Path
|
|
1024
1037
|
dest
|
1025
1038
|
end
|
1026
1039
|
alias_method :ren, :rename
|
1040
|
+
alias_method :rename_to, :rename
|
1027
1041
|
|
1028
1042
|
#
|
1029
1043
|
# Works the same as "rename", but the destination can be on another disk.
|
@@ -1502,7 +1516,8 @@ class Path
|
|
1502
1516
|
# TODO: Remove the tempfile when the Path object is garbage collected or freed.
|
1503
1517
|
#
|
1504
1518
|
def self.tmpfile(prefix="tmp")
|
1505
|
-
path = Path.new(Tempfile.new(prefix).path, unlink_when_garbage_collected: true)
|
1519
|
+
# path = Path.new(Tempfile.new(prefix).path, unlink_when_garbage_collected: true)
|
1520
|
+
path = Path.new(Tempfile.new(prefix).path)
|
1506
1521
|
yield path if block_given?
|
1507
1522
|
path
|
1508
1523
|
end
|
@@ -1633,7 +1648,7 @@ class Path::URI < Path
|
|
1633
1648
|
# TODO: only include certain methods from Path (delegate style)
|
1634
1649
|
# (eg: remove commands that write)
|
1635
1650
|
|
1636
|
-
def initialize(uri, hints
|
1651
|
+
def initialize(uri, **hints)
|
1637
1652
|
@uri = ::URI.parse(uri)
|
1638
1653
|
self.path = @uri.path
|
1639
1654
|
end
|
data/lib/epitools/rash.rb
CHANGED
data/lib/epitools/term.rb
CHANGED
@@ -29,26 +29,62 @@ module Term
|
|
29
29
|
# Return the [width,height] of the terminal.
|
30
30
|
#
|
31
31
|
def size
|
32
|
-
$stdout.winsize.reverse
|
32
|
+
$stdout.winsize.reverse rescue [80,25]
|
33
33
|
end
|
34
34
|
|
35
35
|
def width; size[0]; end
|
36
36
|
def height; size[1]; end
|
37
|
-
def goto(x,y); @x, @y = x, y; end
|
38
|
-
def pos; [@x, @y]; end
|
37
|
+
# def goto(x,y); @x, @y = x, y; end
|
38
|
+
# def pos; [@x, @y]; end
|
39
39
|
|
40
|
-
def clear
|
41
|
-
print "\e[H\e[J"
|
42
|
-
end
|
43
40
|
|
41
|
+
##################################################################################
|
42
|
+
### ANSI Stuff (see: ttps://en.wikipedia.org/wiki/ANSI_escape_code)
|
43
|
+
##################################################################################
|
44
|
+
|
45
|
+
##################################################################################
|
46
|
+
## <n>K = Clear (part of) the line
|
47
|
+
##################################################################################
|
48
|
+
|
49
|
+
# 2 = clear entire line
|
44
50
|
def clear_line
|
45
51
|
print "\e[2K"
|
46
52
|
end
|
47
53
|
|
54
|
+
# 0 = clear to end of line
|
48
55
|
def clear_eol
|
49
56
|
print "\e[0K"
|
50
57
|
end
|
51
58
|
|
59
|
+
##################################################################################
|
60
|
+
## <n>J = Clear (part of) the screen.
|
61
|
+
##################################################################################
|
62
|
+
|
63
|
+
def clear
|
64
|
+
# If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS).
|
65
|
+
print "\e[2J\e[H"
|
66
|
+
end
|
67
|
+
|
68
|
+
def clear_all_above
|
69
|
+
# If n is 1, clear from cursor to beginning of the screen.
|
70
|
+
print "\e[1J"
|
71
|
+
end
|
72
|
+
|
73
|
+
def clear_all_below
|
74
|
+
# If n is 0 (or missing), clear from cursor to end of screen.
|
75
|
+
print "\e[0J"
|
76
|
+
end
|
77
|
+
|
78
|
+
def clear_scrollback_buffer!
|
79
|
+
# If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).
|
80
|
+
print "\e[3J"
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
##################################################################################
|
85
|
+
## <n>;<m>H = Move!
|
86
|
+
##################################################################################
|
87
|
+
|
52
88
|
def move_to(row: 1, col: 1)
|
53
89
|
print "\e[#{row};#{col}H"
|
54
90
|
end
|
@@ -82,11 +118,15 @@ module Term
|
|
82
118
|
@back = back if back
|
83
119
|
end
|
84
120
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
121
|
+
#
|
122
|
+
# curses-style scrollable terminal window
|
123
|
+
#
|
89
124
|
class Window
|
125
|
+
|
126
|
+
# work in progress. probably requires an event loop and a higher order container for having multiple windows and a text-input and stuff.
|
127
|
+
|
128
|
+
attr_accessor :wrap
|
129
|
+
|
90
130
|
def initialize
|
91
131
|
end
|
92
132
|
|
@@ -94,21 +134,39 @@ module Term
|
|
94
134
|
end
|
95
135
|
end
|
96
136
|
|
137
|
+
|
97
138
|
class Table
|
98
139
|
|
99
140
|
# TODO:
|
100
141
|
#
|
101
142
|
# * make Table's configuration eaiser to remember by putting the formatting parameters in initialize
|
102
143
|
# eg: Table.new(elements, :sort=>:vertical).to_s
|
144
|
+
# * strip ansi
|
145
|
+
# * wrap contents
|
146
|
+
# * rounded corners
|
147
|
+
# * [far future] dynamic sortable filterable toggleable table
|
103
148
|
#
|
104
149
|
|
105
150
|
attr_accessor :border, :columns, :padding, :strip_color, :indent, :width, :height
|
106
151
|
|
107
|
-
def self.
|
108
|
-
|
152
|
+
def self.print(thing, **opts)
|
153
|
+
raise "Can't tablize a #{thing.class}" unless thing.class < Enumerable
|
154
|
+
puts new(thing, **opts).display
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.hprint(thing)
|
158
|
+
puts new(thing).in_rows
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.vprint(thing)
|
162
|
+
puts new(thing).in_columns
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.[](data, **opts)
|
166
|
+
new(data, **opts)
|
109
167
|
end
|
110
168
|
|
111
|
-
def initialize(data, options
|
169
|
+
def initialize(data, **options)
|
112
170
|
@data = data.map(&:to_s)
|
113
171
|
@strip_color = options[:ansi] || options[:colorized] || options[:colored] || options[:strip_color] || options[:strip_ansi]
|
114
172
|
|
@@ -185,7 +243,7 @@ module Term
|
|
185
243
|
end
|
186
244
|
alias_method :by_rows, :in_rows
|
187
245
|
|
188
|
-
def display #(opts
|
246
|
+
def display #(**opts)
|
189
247
|
case @direction
|
190
248
|
when :horizontal
|
191
249
|
puts in_rows
|
@@ -198,7 +256,7 @@ module Term
|
|
198
256
|
by_rows
|
199
257
|
end
|
200
258
|
|
201
|
-
def render(rows, options
|
259
|
+
def render(rows, **options)
|
202
260
|
num_cols = rows.first.size
|
203
261
|
result = []
|
204
262
|
|
data/spec/core_ext_spec.rb
CHANGED
@@ -404,6 +404,15 @@ describe String do
|
|
404
404
|
]
|
405
405
|
end
|
406
406
|
|
407
|
+
it "parses units" do
|
408
|
+
"50%".parse_units.should == 0.5
|
409
|
+
"1b".parse_units.should == 1.billion
|
410
|
+
"1gb".parse_units.should == 2**30
|
411
|
+
|
412
|
+
lambda { "whee".parse_units }.should raise_error
|
413
|
+
lambda { "57 butts".parse_units }.should raise_error
|
414
|
+
end
|
415
|
+
|
407
416
|
end
|
408
417
|
|
409
418
|
|
@@ -491,15 +500,30 @@ describe Float do
|
|
491
500
|
end
|
492
501
|
end
|
493
502
|
|
494
|
-
it "
|
503
|
+
it "percents" do
|
495
504
|
f = 0.716237
|
496
|
-
f.percent.should == "
|
505
|
+
f.percent.should == "71.6%"
|
506
|
+
f.percent(0).should == "72%"
|
507
|
+
f.percent(1).should == "71.6%"
|
497
508
|
f.percent(2).should == "71.62%"
|
498
509
|
f.percent(3).should == "71.624%"
|
499
510
|
end
|
500
511
|
|
501
512
|
end
|
502
513
|
|
514
|
+
describe Rational do
|
515
|
+
|
516
|
+
it "makes em" do
|
517
|
+
lambda { Rational[1,2] }.should_not raise_error
|
518
|
+
end
|
519
|
+
|
520
|
+
it "percents" do
|
521
|
+
Rational(1,2).percent.should == "50.0%"
|
522
|
+
Rational(1,3).percent(3).should == "33.333%"
|
523
|
+
end
|
524
|
+
|
525
|
+
end
|
526
|
+
|
503
527
|
describe Number do
|
504
528
|
|
505
529
|
it "number?" do
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'epitools/fraction'
|
2
|
+
|
3
|
+
describe Fraction do
|
4
|
+
|
5
|
+
# before :each do
|
6
|
+
# @a = Fraction[1,1]
|
7
|
+
# @b = Fraction[1,2]
|
8
|
+
# end
|
9
|
+
|
10
|
+
it "adds normally" do
|
11
|
+
( Fraction[1,1] + Fraction[1,2] ).should == Fraction[3,2]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "doesn't let you add weird stuff together" do
|
15
|
+
-> { Fraction[1,2] + :splunge }.should raise_error(TypeError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "timeses normally" do
|
19
|
+
( Fraction[1,1] * 2 ).should == Fraction[2,2]
|
20
|
+
( Fraction[1,2] * 2 ).should == Fraction[2,4]
|
21
|
+
( Fraction[1,1] * Fraction[1,2] ).should == Fraction[1,2]
|
22
|
+
( Fraction[5,3] * Fraction[1,2] ).should == Fraction[5*1, 2*3]
|
23
|
+
( Fraction[5,3] * Fraction[1,2] ).should == Fraction[5, 6]
|
24
|
+
( Fraction[1,2] * Fraction[1,2] ).should == Fraction[1, 4]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "doesn't let you times it with weird stuff" do
|
28
|
+
-> { Fraction[1,2] * ([:ayeeee]*100) }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "floats" do
|
32
|
+
Fraction[1,1].to_f.should == 1.0
|
33
|
+
Fraction[1,2].to_f.should == 0.5
|
34
|
+
|
35
|
+
-> { Fraction[1,0].to_f }.should raise_error(ZeroDivisionError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "percents" do
|
39
|
+
Fraction[1,1].percent.should == "100.0%"
|
40
|
+
Fraction[1,2].percent.should == "50.0%"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "simplifies" do
|
44
|
+
Fraction[2,4].simplify.should == Fraction[1,2]
|
45
|
+
Fraction[4,2].simplify.should == Fraction[2,1]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has a function-style wrapper! (for paren fans)" do
|
49
|
+
Fraction(1,2).should == Fraction[1,2]
|
50
|
+
Fraction(1,2).should == Fraction.new(1,2)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/numwords_spec.rb
CHANGED
@@ -7,17 +7,14 @@ describe Numeric do
|
|
7
7
|
10 => "ten",
|
8
8
|
3_123 => "three thousand, one-hundred and twenty-three",
|
9
9
|
123_124 => "one-hundred and twenty-three thousand, one-hundred and twenty-four",
|
10
|
-
|
11
10
|
8_128_937_981_273_987_129_837_174_612_897_638_613 => "eight undecillion, one-hundred and twenty-eight decillion, nine-hundred and thirty-seven nonillion, nine-hundred and eighty-one octillion, two-hundred and seventy-three septillion, nine-hundred and eighty-seven sextillion, one-hundred and twenty-nine quintillion, eight-hundred and thirty-seven quadrillion, one-hundred and seventy-four trillion, six-hundred and twelve billion, eight-hundred and ninety-seven million, six-hundred and thirty-eight thousand, six-hundred and thirteen",
|
12
|
-
|
13
|
-
3_486_597_230_495_871_304_981_320_498_123_498_263_984_739_841_834_091_823_094_812_039_481_231_623_987_461_293_874_698_123_649_817_236 => "three duotrigintillion, four-hundred and eighty-six untrigintillion, five-hundred and ninety-seven trigintillion, two-hundred and thirty novemvigintillion, four-hundred and ninety-five octovigintillion, eight-hundred and seventy-one septenvigintillion, three-hundred and four sexvigintillion, nine-hundred and eighty-one quinvigintillion, three-hundred and twenty quattuorvigintillion, four-hundred and ninety-eight trevigintillion, one-hundred and twenty-three duovigintillion, four-hundred and ninety-eight unvigintillion, two-hundred and sixty-three vigintillion, nine-hundred and eighty-four novemdecillion, seven-hundred and thirty-nine octodecillion, eight-hundred and fourty-one septendecillion, eight-hundred and thirty-four sexdecillion, ninety-one quindecillion, eight-hundred and twenty-three quattuordecillion, ninety-four tredecillion, eight-hundred and twelve duodecillion, thirty-nine undecillion, four-hundred and eighty-one decillion, two-hundred and thirty-one nonillion, six-hundred and twenty-three octillion, nine-hundred and eighty-seven septillion, four-hundred and sixty-one sextillion, two-hundred and ninety-three quintillion, eight-hundred and seventy-four quadrillion, six-hundred and ninety-eight trillion, one-hundred and twenty-three billion, six-hundred and fourty-nine million, eight-hundred and seventeen thousand, two-hundred and thirty-six",
|
14
|
-
|
11
|
+
3_486_597_230_495_871_304_981_320_498_123_498_263_984_739_841_834_091_823_094_812_039_481_231_623_987_461_293_874_698_123_649_817_236 => "three duotrigintillion, four-hundred and eighty-six untrigintillion, five-hundred and ninety-seven trigintillion, two-hundred and thirty novemvigintillion, four-hundred and ninety-five octovigintillion, eight-hundred and seventy-one septenvigintillion, three-hundred and four sexvigintillion, nine-hundred and eighty-one quinvigintillion, three-hundred and twenty quattuorvigintillion, four-hundred and ninety-eight trevigintillion, one-hundred and twenty-three duovigintillion, four-hundred and ninety-eight unvigintillion, two-hundred and sixty-three vigintillion, nine-hundred and eighty-four novemdecillion, seven-hundred and thirty-nine octodecillion, eight-hundred and forty-one septendecillion, eight-hundred and thirty-four sexdecillion, ninety-one quindecillion, eight-hundred and twenty-three quattuordecillion, ninety-four tredecillion, eight-hundred and twelve duodecillion, thirty-nine undecillion, four-hundred and eighty-one decillion, two-hundred and thirty-one nonillion, six-hundred and twenty-three octillion, nine-hundred and eighty-seven septillion, four-hundred and sixty-one sextillion, two-hundred and ninety-three quintillion, eight-hundred and seventy-four quadrillion, six-hundred and ninety-eight trillion, one-hundred and twenty-three billion, six-hundred and forty-nine million, eight-hundred and seventeen thousand, two-hundred and thirty-six",
|
15
12
|
1763241823498172490817349807213409238409123409128340981234781236487126348791263847961238794612839468917236489712364987162398746129834698172364987123 => "more than a googol! (148 digits)"
|
16
13
|
}.each do |num, result|
|
17
14
|
num.to_words.should == result
|
18
15
|
end
|
19
16
|
|
20
|
-
lambda{ 1.523.million.billion.to_words }.should_not raise_error
|
17
|
+
lambda { 1.523.million.billion.to_words }.should_not raise_error
|
21
18
|
end
|
22
19
|
|
23
20
|
it "has .thousand, .million, etc." do
|
data/spec/path_spec.rb
CHANGED
@@ -147,7 +147,9 @@ describe Path do
|
|
147
147
|
data = "<h1>The best webpage in the universe.</h1>"
|
148
148
|
html = Path.tmpfile
|
149
149
|
html.write data
|
150
|
-
|
150
|
+
|
151
|
+
# html.read_html.at("h1").to_s.should == data
|
152
|
+
html.read_html.at_css("h1").to_s.should == data
|
151
153
|
|
152
154
|
ensure
|
153
155
|
yaml.rm
|
@@ -243,7 +245,7 @@ describe Path do
|
|
243
245
|
|
244
246
|
old_name = path.to_s
|
245
247
|
|
246
|
-
dest = path.rename(:
|
248
|
+
dest = path.rename(path.with(ext: ".dat"))
|
247
249
|
|
248
250
|
dest.to_s.should == old_name+".dat"
|
249
251
|
path.to_s.should == old_name
|
@@ -253,10 +255,10 @@ describe Path do
|
|
253
255
|
path.exists?.should == false
|
254
256
|
|
255
257
|
path.touch
|
256
|
-
lambda { path.rename(:
|
258
|
+
lambda { path.rename(path.with(ext: ".dat")) }.should raise_error(RuntimeError)
|
257
259
|
|
258
260
|
dest.rm
|
259
|
-
path.rename!(:
|
261
|
+
path.rename!(path.with(ext: ".dat"))
|
260
262
|
path.to_s.should_not == old_name
|
261
263
|
path.exists?.should == true
|
262
264
|
|
@@ -413,6 +415,14 @@ describe Path do
|
|
413
415
|
|
414
416
|
# system("gzip -c < #{tmpjson} > #{tmpjson}.gz")
|
415
417
|
|
418
|
+
# class method version
|
419
|
+
Path.zopen("#{tmpjson}.gz", "w") { |io| io.write(JSON.dump(hash)) }
|
420
|
+
tmpgzip = Path["#{tmpjson}.gz"]
|
421
|
+
tmpgzip.exists?.should == true
|
422
|
+
tmpgzip.size.should be > 0
|
423
|
+
tmpgzip&.rm
|
424
|
+
|
425
|
+
# instance method version
|
416
426
|
tmpgzip = Path["#{tmpjson}.gz"]
|
417
427
|
tmpgzip.zopen("w") { |io| io.write(JSON.dump(hash)) }
|
418
428
|
tmpgzip.exists?.should == true
|
data/spec/sys_spec.rb
CHANGED
@@ -30,6 +30,11 @@ describe Sys::ProcessInfo do
|
|
30
30
|
if p2 = p2s[p1.pid]
|
31
31
|
matches += 1
|
32
32
|
p1.command.should == p2.command
|
33
|
+
|
34
|
+
# FIXME: this behaves weirdly with kernel processes, eg:
|
35
|
+
# expected: "[kworker/u8:1-phy5]"
|
36
|
+
# got: "[kworker/u8:1-events_unbound]" (using ==)
|
37
|
+
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
data/spec/zopen_spec.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'epitools/zopen'
|
2
|
-
require 'tempfile'
|
1
|
+
# require 'epitools/zopen'
|
2
|
+
# require 'tempfile'
|
3
3
|
|
4
|
-
describe "zopen()" do
|
4
|
+
# describe "zopen()" do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# before :all do
|
7
|
+
# @data = ("x"*100+"\n") * 1000
|
8
|
+
# @tmp = Tempfile.new("zopen_spec")
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# @plainfile = @tmp.path
|
11
|
+
# @gzfile = "#{@tmp.path}.gz"
|
12
|
+
# end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# after :all do
|
15
|
+
# File.unlink @plainfile
|
16
|
+
# File.unlink @gzfile
|
17
|
+
# end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
# it "writes/reads a gz" do
|
20
|
+
# f = zopen(@gzfile, "w")
|
21
|
+
# f.write(@data).should == @data.size
|
22
|
+
# f.close
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# f = zopen(@gzfile, "r")
|
25
|
+
# f.read.should == @data
|
26
|
+
# f.close
|
27
|
+
# end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
# it "writes/reads non-gz files" do
|
30
|
+
# zopen(@plainfile, "w") {|f| f.write(@data) }
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
# # readstyle
|
33
|
+
# File.read(@plainfile).should == zopen(@plainfile).read
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# # blockstyle
|
36
|
+
# open(@plainfile){|f| f.read }.should == zopen(@plainfile){|f| f.read }
|
37
|
+
# end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
# it "is enumerable" do
|
40
|
+
# zopen(@gzfile) do |f|
|
41
|
+
# f.respond_to?(:each).should == true
|
42
|
+
# f.respond_to?(:map).should == true
|
43
|
+
# f.respond_to?(:inject).should == true
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
# f.all?{|line| line =~ /^x+$/ }
|
46
|
+
# end
|
47
|
+
# end
|
48
48
|
|
49
|
-
end
|
49
|
+
# 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.
|
4
|
+
version: 0.5.136
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -69,6 +69,8 @@ files:
|
|
69
69
|
- lib/epitools/core_ext/truthiness.rb
|
70
70
|
- lib/epitools/core_ext/uri.rb
|
71
71
|
- lib/epitools/daemonize.rb
|
72
|
+
- lib/epitools/fraction.rb
|
73
|
+
- lib/epitools/gem_ext/oga.rb
|
72
74
|
- lib/epitools/hexdump.rb
|
73
75
|
- lib/epitools/iter.rb
|
74
76
|
- lib/epitools/its.rb
|
@@ -85,7 +87,6 @@ files:
|
|
85
87
|
- lib/epitools/progressbar.rb
|
86
88
|
- lib/epitools/rails.rb
|
87
89
|
- lib/epitools/rash.rb
|
88
|
-
- lib/epitools/ratio.rb
|
89
90
|
- lib/epitools/semantic_version.rb
|
90
91
|
- lib/epitools/slop.rb
|
91
92
|
- lib/epitools/slop/LICENSE
|
@@ -104,14 +105,16 @@ files:
|
|
104
105
|
- lib/epitools/wm.rb
|
105
106
|
- spec/.rspec
|
106
107
|
- spec/autoreq_spec.rb
|
107
|
-
- spec/browser_spec.rb
|
108
108
|
- spec/btree_spec.rb
|
109
109
|
- spec/clitools_spec.rb
|
110
110
|
- spec/colored_spec.rb
|
111
111
|
- spec/core_ext_spec.rb
|
112
|
+
- spec/fraction_spec.rb
|
112
113
|
- spec/histogram_spec.rb
|
113
114
|
- spec/iter_spec.rb
|
114
115
|
- spec/lcs_spec.rb
|
116
|
+
- spec/manual/browser_spec.rb
|
117
|
+
- spec/manual/wm_spec.rb
|
115
118
|
- spec/numwords_spec.rb
|
116
119
|
- spec/path_spec.rb
|
117
120
|
- spec/permutations_spec.rb
|
@@ -121,7 +124,6 @@ files:
|
|
121
124
|
- spec/sys_spec.rb
|
122
125
|
- spec/term_spec.rb
|
123
126
|
- spec/typed_struct_spec.rb
|
124
|
-
- spec/wm_spec.rb
|
125
127
|
- spec/zopen_spec.rb
|
126
128
|
homepage: http://github.com/epitron/epitools
|
127
129
|
licenses:
|
@@ -142,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
144
|
- !ruby/object:Gem::Version
|
143
145
|
version: '0'
|
144
146
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.3.25
|
146
148
|
signing_key:
|
147
149
|
specification_version: 3
|
148
150
|
summary: Not utils... METILS!
|