epitools 0.5.111 → 0.5.112
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 +1 -1
- data/VERSION +1 -1
- data/lib/epitools/autoloads.rb +2 -0
- data/lib/epitools/browser.rb +1 -1
- data/lib/epitools/core_ext/array.rb +72 -0
- data/lib/epitools/core_ext/enumerable.rb +26 -0
- data/lib/epitools/core_ext/hash.rb +29 -0
- data/lib/epitools/core_ext/matrix.rb +11 -0
- data/lib/epitools/core_ext/numbers.rb +1 -1
- data/lib/epitools/core_ext/string.rb +7 -0
- data/lib/epitools/path.rb +102 -38
- data/spec/core_ext_spec.rb +45 -2
- data/spec/path_spec.rb +21 -5
- 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: d59d9daf2f46a0daf7008b75f596bcb8164801c61ec00a8a4f779e3105e97be1
|
4
|
+
data.tar.gz: 97b7ef67560c7377929db8aece4fc6f7f358f3ef96501c5913f99b75a655fa07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c17bdd3fada9128955712952cfa8edfa459ff24f83fd04ba4cef9116c3a931f9caba819095a4131f24c89bc4921d574110f6ccd180310a721c5d072896901e40
|
7
|
+
data.tar.gz: b642d62d3c9326b2b20a85ebb8bbf92ca5cff1150c6093f7f73530c44b878ef9637a36a8f2649fcac0e4bc22fca1de75469b947f99a648d77082f4d544f08161
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.112
|
data/lib/epitools/autoloads.rb
CHANGED
@@ -16,6 +16,7 @@ autoload :Timeout, 'timeout'
|
|
16
16
|
autoload :Find, 'find'
|
17
17
|
autoload :Benchmark, 'benchmark'
|
18
18
|
autoload :Tracer, 'tracer'
|
19
|
+
autoload :TSort, 'tsort'
|
19
20
|
autoload :Shellwords, 'shellwords'
|
20
21
|
autoload :PTY, 'pty'
|
21
22
|
autoload :CSV, 'csv'
|
@@ -86,6 +87,7 @@ autoreq :JSON, 'json'
|
|
86
87
|
autoreq :GeoIP, 'geoip'
|
87
88
|
autoreq :RBTree, 'rbtree'
|
88
89
|
autoreq :MultiRBTree, 'rbtree'
|
90
|
+
autoreq :ID3Tag, 'id3tag'
|
89
91
|
|
90
92
|
autoreq :AwesomePrint do
|
91
93
|
require 'awesome_print'
|
data/lib/epitools/browser.rb
CHANGED
@@ -61,7 +61,7 @@ class Browser
|
|
61
61
|
@agent = Mechanize.new do |a|
|
62
62
|
# ["Mechanize", "Mac Mozilla", "Linux Mozilla", "Windows IE 6", "iPhone", "Linux Konqueror", "Windows IE 7", "Mac FireFox", "Mac Safari", "Windows Mozilla"]
|
63
63
|
a.max_history = 10
|
64
|
-
a.user_agent_alias = "Windows
|
64
|
+
a.user_agent_alias = "Windows Chrome"
|
65
65
|
a.log = Logger.new "mechanize.log" if @use_logs
|
66
66
|
end
|
67
67
|
|
@@ -136,6 +136,78 @@ class Array
|
|
136
136
|
|
137
137
|
alias_method :unzip, :transpose
|
138
138
|
|
139
|
+
#
|
140
|
+
# Transpose an array that could have rows of uneven length
|
141
|
+
#
|
142
|
+
def transpose_with_padding
|
143
|
+
max_width = map(&:size).max
|
144
|
+
map { |row| row.rpad(max_width) }.transpose
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Remove instances of "element" from the end of the array (using `Array#pop`)
|
149
|
+
#
|
150
|
+
def rtrim!(element=nil)
|
151
|
+
pop while last == element
|
152
|
+
self
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# Like `rtrim!`, but returns a trimmed copy of the array
|
157
|
+
#
|
158
|
+
def rtrim(element=nil)
|
159
|
+
dup.rtrim!(element)
|
160
|
+
end
|
161
|
+
|
162
|
+
####################################################################
|
163
|
+
# Pseudo-matrix methods
|
164
|
+
####################################################################
|
165
|
+
|
166
|
+
def rows
|
167
|
+
self
|
168
|
+
end
|
169
|
+
|
170
|
+
def columns
|
171
|
+
cols = transpose_with_padding
|
172
|
+
cols.each &:rtrim!
|
173
|
+
cols
|
174
|
+
end
|
175
|
+
alias_method :cols, :columns
|
176
|
+
|
177
|
+
#
|
178
|
+
# Return row n of a 2D array
|
179
|
+
#
|
180
|
+
def row(n)
|
181
|
+
rows[n]
|
182
|
+
end
|
183
|
+
|
184
|
+
#
|
185
|
+
# Return column n of a 2D array
|
186
|
+
#
|
187
|
+
def column(n)
|
188
|
+
columns[n]&.rtrim!
|
189
|
+
end
|
190
|
+
alias_method :col, :column
|
191
|
+
|
192
|
+
####################################################################
|
193
|
+
|
194
|
+
#
|
195
|
+
# Extend the array the target_width by adding nils to the end (right side)
|
196
|
+
#
|
197
|
+
def rpad!(target_width)
|
198
|
+
if target_width > size and target_width > 0
|
199
|
+
self[target_width-1] = nil
|
200
|
+
end
|
201
|
+
self
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Return a copy of this array which has been extended to target_width by adding nils to the end (right side)
|
206
|
+
#
|
207
|
+
def rpad(target_width)
|
208
|
+
dup.rpad!(target_width)
|
209
|
+
end
|
210
|
+
|
139
211
|
#
|
140
212
|
# Convert the array to a hash
|
141
213
|
#
|
@@ -470,6 +470,32 @@ module Enumerable
|
|
470
470
|
end
|
471
471
|
alias_method :grouped, :groups
|
472
472
|
|
473
|
+
#
|
474
|
+
# run-length encode the array (returns an array of [count, element] pairs)
|
475
|
+
#
|
476
|
+
def rle
|
477
|
+
return to_enum(:rle) unless block_given?
|
478
|
+
|
479
|
+
last = nil
|
480
|
+
result = []
|
481
|
+
count = 1
|
482
|
+
|
483
|
+
each do |e|
|
484
|
+
if last
|
485
|
+
if last != e
|
486
|
+
yield [count, last]
|
487
|
+
count = 1
|
488
|
+
else
|
489
|
+
count += 1
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
last = e
|
494
|
+
end
|
495
|
+
|
496
|
+
yield [count, last]
|
497
|
+
end
|
498
|
+
|
473
499
|
#
|
474
500
|
# Sort strings by their numerical values
|
475
501
|
#
|
@@ -53,6 +53,7 @@ class Hash
|
|
53
53
|
end
|
54
54
|
self
|
55
55
|
end
|
56
|
+
alias_method :transform_keys!, :map_keys!
|
56
57
|
|
57
58
|
#
|
58
59
|
# Transforms the keys of the hash by passing them into the supplied block,
|
@@ -61,6 +62,34 @@ class Hash
|
|
61
62
|
def map_keys(&block)
|
62
63
|
dup.map_keys!(&block)
|
63
64
|
end
|
65
|
+
alias_method :transform_keys, :map_keys
|
66
|
+
|
67
|
+
#
|
68
|
+
# Translate keys to other keys, given a hash of old-key to new-key mappings.
|
69
|
+
#
|
70
|
+
# eg: hash.translate_keys!(
|
71
|
+
# "Extreme Sports!!!!" => :extreme_sports,
|
72
|
+
# "Mediocre sports" => :sports,
|
73
|
+
# "Pretty okay sports" => :sports,
|
74
|
+
# "Golf" => :liesure_activities,
|
75
|
+
# )
|
76
|
+
#
|
77
|
+
def translate_keys!(mapping)
|
78
|
+
# TODO: Allow regexes and lambdas (eg: translate_keys!(/.+/ => ->(key) { key.to_sym })
|
79
|
+
mapping.each do |src,dest|
|
80
|
+
if includes? src
|
81
|
+
self[dest] = delete(src)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Same as `translate_keys!`, except it returns a copy of the hash
|
89
|
+
#
|
90
|
+
def translate_keys(mapping)
|
91
|
+
dup.translate_keys!(mapping)
|
92
|
+
end
|
64
93
|
|
65
94
|
#
|
66
95
|
# Convert the keys to symbols in-place, for fun and profit
|
@@ -1,3 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# TODO: Reimplement Matrix so it's not so awful, and give it a new name (like Grid).
|
3
|
+
# (Goal: To be as nice as numpy)
|
4
|
+
#
|
5
|
+
# Features:
|
6
|
+
# * Better constructors
|
7
|
+
# * Pretty-printer support
|
8
|
+
# * .rows, .cols, .each_{row,col}, .neighbourhood
|
9
|
+
# * Vec class, Point class
|
10
|
+
#
|
11
|
+
|
1
12
|
require 'matrix'
|
2
13
|
|
3
14
|
#
|
data/lib/epitools/path.rb
CHANGED
@@ -157,10 +157,7 @@ class Path
|
|
157
157
|
when String
|
158
158
|
|
159
159
|
if path =~ %r{^[a-z\-]+://}i # URL?
|
160
|
-
Path::
|
161
|
-
|
162
|
-
elsif path =~ /^javascript:/
|
163
|
-
Path::JS.new(path)
|
160
|
+
Path::URI.new(path)
|
164
161
|
|
165
162
|
else
|
166
163
|
# TODO: highlight backgrounds of codeblocks to show indent level & put boxes (or rules?) around (between?) double-spaced regions
|
@@ -452,13 +449,8 @@ class Path
|
|
452
449
|
!!thing[/^\../]
|
453
450
|
end
|
454
451
|
|
455
|
-
def uri
|
456
|
-
|
457
|
-
end
|
458
|
-
|
459
|
-
def url?
|
460
|
-
uri?
|
461
|
-
end
|
452
|
+
def uri?; false; end
|
453
|
+
def url?; uri?; end
|
462
454
|
|
463
455
|
def child_of?(parent)
|
464
456
|
parent.parent_of? self
|
@@ -468,6 +460,13 @@ class Path
|
|
468
460
|
dirs == child.dirs[0...dirs.size]
|
469
461
|
end
|
470
462
|
|
463
|
+
#
|
464
|
+
# Does the file or directory name start with a "."?
|
465
|
+
#
|
466
|
+
def hidden?
|
467
|
+
(dir? ? dirs.last : filename)[/^\../]
|
468
|
+
end
|
469
|
+
|
471
470
|
###############################################################################
|
472
471
|
# Comparisons
|
473
472
|
###############################################################################
|
@@ -478,7 +477,7 @@ class Path
|
|
478
477
|
# An array of attributes which will be used sort paths (case insensitive, directories come first)
|
479
478
|
#
|
480
479
|
def sort_attrs
|
481
|
-
[filename ? 1 : 0, path.downcase]
|
480
|
+
[(filename ? 1 : 0), path.downcase]
|
482
481
|
end
|
483
482
|
|
484
483
|
def <=>(other)
|
@@ -495,7 +494,9 @@ class Path
|
|
495
494
|
def ==(other)
|
496
495
|
self.path == other.to_s
|
497
496
|
end
|
497
|
+
alias_method :eql?, :==
|
498
498
|
|
499
|
+
def hash; path.hash; end
|
499
500
|
|
500
501
|
###############################################################################
|
501
502
|
# Joining paths
|
@@ -619,6 +620,9 @@ class Path
|
|
619
620
|
# Opening/Reading files
|
620
621
|
###############################################################################
|
621
622
|
|
623
|
+
#
|
624
|
+
# Open the file (default: read-only + binary mode)
|
625
|
+
#
|
622
626
|
def open(mode="rb", &block)
|
623
627
|
if block_given?
|
624
628
|
File.open(path, mode, &block)
|
@@ -629,16 +633,19 @@ class Path
|
|
629
633
|
alias_method :io, :open
|
630
634
|
alias_method :stream, :open
|
631
635
|
|
636
|
+
#
|
637
|
+
# Read bytes from the file (just a wrapper around File.read)
|
638
|
+
#
|
632
639
|
def read(length=nil, offset=nil)
|
633
640
|
File.read(path, length, offset)
|
634
641
|
end
|
635
642
|
|
636
643
|
#
|
637
|
-
# Read the contents of
|
644
|
+
# Read the contents of a file one chunk at a time (default chunk size is 16k)
|
638
645
|
#
|
639
646
|
def each_chunk(chunk_size=2**14)
|
640
|
-
open do |
|
641
|
-
yield
|
647
|
+
open do |io|
|
648
|
+
yield io.read(chunk_size) until io.eof?
|
642
649
|
end
|
643
650
|
end
|
644
651
|
|
@@ -646,12 +653,18 @@ class Path
|
|
646
653
|
#
|
647
654
|
# All the lines in this file, chomped.
|
648
655
|
#
|
649
|
-
def
|
650
|
-
io.each_line
|
656
|
+
def each_line(&block)
|
657
|
+
open { |io| io.each_line { |line| block.call(line.chomp) } }
|
651
658
|
end
|
652
|
-
alias_method :
|
653
|
-
alias_method :lines,
|
659
|
+
alias_method :each, :each_line
|
660
|
+
alias_method :lines, :each_line
|
661
|
+
alias_method :nicelines, :each_line
|
662
|
+
alias_method :nice_lines, :each_line
|
654
663
|
|
664
|
+
|
665
|
+
#
|
666
|
+
# Yields all matching lines in the file (by returning an Enumerator, or receiving a block)
|
667
|
+
#
|
655
668
|
def grep(pat)
|
656
669
|
return to_enum(:grep, pat).to_a unless block_given?
|
657
670
|
|
@@ -660,21 +673,22 @@ class Path
|
|
660
673
|
end
|
661
674
|
end
|
662
675
|
|
663
|
-
def nicelines
|
664
|
-
lines.map(&:chomp)
|
665
|
-
end
|
666
|
-
alias_method :nice_lines, :nicelines
|
667
|
-
|
668
676
|
def unmarshal
|
669
677
|
read.unmarshal
|
670
678
|
end
|
671
679
|
|
680
|
+
#
|
681
|
+
# Returns all the files in the directory that this path points to
|
682
|
+
#
|
672
683
|
def ls
|
673
684
|
Dir.foreach(path).
|
674
685
|
reject {|fn| fn == "." or fn == ".." }.
|
675
686
|
flat_map {|fn| self / fn }
|
676
687
|
end
|
677
688
|
|
689
|
+
#
|
690
|
+
# Returns all files in this path's directory and its subdirectories
|
691
|
+
#
|
678
692
|
def ls_r(symlinks=false)
|
679
693
|
# glob = symlinks ? "**{,/*/**}/*" : "**/*"
|
680
694
|
# Path[File.join(path, glob)]
|
@@ -682,20 +696,33 @@ class Path
|
|
682
696
|
end
|
683
697
|
alias_method :ls_R, :ls_r
|
684
698
|
|
699
|
+
#
|
700
|
+
# Returns all the directories in this path
|
701
|
+
#
|
685
702
|
def ls_dirs
|
686
703
|
ls.select(&:dir?)
|
687
704
|
#Dir.glob("#{path}*/", File::FNM_DOTMATCH).map { |s| Path.new(s, :type=>:dir) }
|
688
705
|
end
|
689
706
|
|
707
|
+
#
|
708
|
+
# Returns all the files in this path
|
709
|
+
#
|
690
710
|
def ls_files
|
691
711
|
ls.select(&:file?)
|
692
712
|
#Dir.glob("#{path}*", File::FNM_DOTMATCH).map { |s| Path.new(s, :type=>:file) }
|
693
713
|
end
|
694
714
|
|
715
|
+
#
|
716
|
+
# Returns all neighbouring directories to this path
|
717
|
+
#
|
695
718
|
def siblings
|
696
719
|
Path[dir].ls - [self]
|
697
720
|
end
|
698
721
|
|
722
|
+
#
|
723
|
+
# Like the unix `touch` command
|
724
|
+
# (if the file exists, update its timestamp, otherwise create a new file)
|
725
|
+
#
|
699
726
|
def touch
|
700
727
|
open("a") { }
|
701
728
|
self
|
@@ -758,7 +785,7 @@ class Path
|
|
758
785
|
|
759
786
|
#
|
760
787
|
# Parse the file based on the file extension.
|
761
|
-
# (Handles json, html, yaml, xml,
|
788
|
+
# (Handles json, html, yaml, xml, csv, marshal, and bson.)
|
762
789
|
#
|
763
790
|
def parse
|
764
791
|
case ext.downcase
|
@@ -823,29 +850,43 @@ class Path
|
|
823
850
|
end
|
824
851
|
alias_method :from_csv, :read_csv
|
825
852
|
|
826
|
-
|
853
|
+
# Parse the file as XML
|
827
854
|
def read_xml
|
828
855
|
Nokogiri::XML(io)
|
829
856
|
end
|
830
857
|
|
831
|
-
|
858
|
+
# Parse the file as a Ruby Marshal dump
|
832
859
|
def read_marshal
|
833
860
|
Marshal.load(io)
|
834
861
|
end
|
835
862
|
|
863
|
+
# Serilize an object to Ruby Marshal format and write it to this path
|
836
864
|
def write_marshal(object)
|
837
865
|
write object.marshal
|
838
866
|
end
|
839
867
|
|
840
|
-
|
868
|
+
# Parse the file as BSON
|
841
869
|
def read_bson
|
842
870
|
BSON.deserialize(read)
|
843
871
|
end
|
844
872
|
|
873
|
+
# Serilize an object to BSON format and write it to this path
|
845
874
|
def write_bson(object)
|
846
875
|
write BSON.serialize(object)
|
847
876
|
end
|
848
877
|
|
878
|
+
#
|
879
|
+
# Read ID3 tags (requires 'id3tag' gem)
|
880
|
+
#
|
881
|
+
# Available fields:
|
882
|
+
# tag.artist, tag.title, tag.album, tag.year, tag.track_nr, tag.genre, tag.get_frame(:TIT2)&.content,
|
883
|
+
# tag.get_frames(:COMM).first&.content, tag.get_frames(:COMM).last&.language
|
884
|
+
#
|
885
|
+
def id3
|
886
|
+
ID3Tag.read(io)
|
887
|
+
end
|
888
|
+
alias_method :id3tags, :id3
|
889
|
+
|
849
890
|
#
|
850
891
|
# Change into the directory. If a block is given, it changes into
|
851
892
|
# the directory for the duration of the block, then puts you back where you
|
@@ -928,7 +969,11 @@ class Path
|
|
928
969
|
|
929
970
|
n = 1
|
930
971
|
loop do
|
931
|
-
|
972
|
+
if dir?
|
973
|
+
new_file = with(:dirs => dirs[0..-2] + ["#{dirs.last} (#{n})"])
|
974
|
+
else
|
975
|
+
new_file = with(:basename => "#{basename} (#{n})")
|
976
|
+
end
|
932
977
|
return new_file unless new_file.exists?
|
933
978
|
n += 1
|
934
979
|
end
|
@@ -1074,7 +1119,12 @@ class Path
|
|
1074
1119
|
|
1075
1120
|
## Dangerous methods.
|
1076
1121
|
|
1122
|
+
#
|
1123
|
+
# Remove a file or directory
|
1124
|
+
#
|
1077
1125
|
def rm
|
1126
|
+
raise "Error: #{self} does not exist" unless symlink? or exists?
|
1127
|
+
|
1078
1128
|
if directory? and not symlink?
|
1079
1129
|
Dir.rmdir(self) == 0
|
1080
1130
|
else
|
@@ -1085,6 +1135,9 @@ class Path
|
|
1085
1135
|
alias_method :unlink!, :rm
|
1086
1136
|
alias_method :remove!, :rm
|
1087
1137
|
|
1138
|
+
#
|
1139
|
+
# Shrink or expand the size of a file in-place
|
1140
|
+
#
|
1088
1141
|
def truncate(offset=0)
|
1089
1142
|
File.truncate(self, offset) if exists?
|
1090
1143
|
end
|
@@ -1313,12 +1366,12 @@ class Path
|
|
1313
1366
|
chown_R/1
|
1314
1367
|
chmod_R/1
|
1315
1368
|
].each do |spec|
|
1316
|
-
|
1317
|
-
cardinality
|
1369
|
+
meth, cardinality = spec.split("/")
|
1370
|
+
cardinality = cardinality.to_i
|
1318
1371
|
|
1319
1372
|
class_eval %{
|
1320
|
-
def self.#{
|
1321
|
-
Path[path].#{
|
1373
|
+
def self.#{meth}(path#{", *args" if cardinality > 0})
|
1374
|
+
Path[path].#{meth}#{"(*args)" if cardinality > 0}
|
1322
1375
|
end
|
1323
1376
|
}
|
1324
1377
|
end
|
@@ -1355,16 +1408,21 @@ class Path
|
|
1355
1408
|
end
|
1356
1409
|
alias_class_method :tempdir, :tmpdir
|
1357
1410
|
|
1358
|
-
|
1411
|
+
#
|
1412
|
+
# User's current home directory
|
1413
|
+
#
|
1359
1414
|
def self.home
|
1360
1415
|
Path[ENV['HOME']]
|
1361
1416
|
end
|
1362
1417
|
|
1418
|
+
#
|
1419
|
+
# The current directory
|
1420
|
+
#
|
1363
1421
|
def self.pwd
|
1364
1422
|
Path.new expand_path(Dir.pwd)
|
1365
1423
|
end
|
1366
1424
|
|
1367
|
-
def self.pushd
|
1425
|
+
def self.pushd(destination)
|
1368
1426
|
@@dir_stack ||= []
|
1369
1427
|
@@dir_stack.push pwd
|
1370
1428
|
end
|
@@ -1453,9 +1511,9 @@ class Path::Relative < Path
|
|
1453
1511
|
end
|
1454
1512
|
|
1455
1513
|
#
|
1456
|
-
# A wrapper for
|
1514
|
+
# A wrapper for URI objects.
|
1457
1515
|
#
|
1458
|
-
class Path::
|
1516
|
+
class Path::URI < Path
|
1459
1517
|
|
1460
1518
|
attr_reader :uri
|
1461
1519
|
|
@@ -1464,7 +1522,7 @@ class Path::URL < Path
|
|
1464
1522
|
# (eg: remove commands that write)
|
1465
1523
|
|
1466
1524
|
def initialize(uri, hints={})
|
1467
|
-
@uri = URI.parse(uri)
|
1525
|
+
@uri = ::URI.parse(uri)
|
1468
1526
|
self.path = @uri.path
|
1469
1527
|
end
|
1470
1528
|
|
@@ -1486,6 +1544,12 @@ class Path::URL < Path
|
|
1486
1544
|
def scheme; uri.scheme; end
|
1487
1545
|
alias_method :protocol, :scheme
|
1488
1546
|
|
1547
|
+
%w[http https ftp magnet].each do |s|
|
1548
|
+
define_method("#{s}?") { scheme[/^#{s}$/i] }
|
1549
|
+
end
|
1550
|
+
|
1551
|
+
def http?; super or https?; end
|
1552
|
+
|
1489
1553
|
#
|
1490
1554
|
# ...and this is: 'host.com'
|
1491
1555
|
#
|
data/spec/core_ext_spec.rb
CHANGED
@@ -196,6 +196,7 @@ describe Numeric do
|
|
196
196
|
|
197
197
|
end
|
198
198
|
|
199
|
+
|
199
200
|
describe String do
|
200
201
|
|
201
202
|
it "anys?" do
|
@@ -204,8 +205,6 @@ describe String do
|
|
204
205
|
"YAY".should be_any
|
205
206
|
end
|
206
207
|
|
207
|
-
|
208
|
-
|
209
208
|
it "rot13s" do
|
210
209
|
message = "Unbreakable Code"
|
211
210
|
message.rot13.should_not == message
|
@@ -429,6 +428,7 @@ describe Integer do
|
|
429
428
|
|
430
429
|
end
|
431
430
|
|
431
|
+
|
432
432
|
describe Float do
|
433
433
|
|
434
434
|
it "float?" do
|
@@ -462,6 +462,7 @@ describe Number do
|
|
462
462
|
|
463
463
|
end
|
464
464
|
|
465
|
+
|
465
466
|
describe Array do
|
466
467
|
|
467
468
|
it "squashes" do
|
@@ -522,6 +523,41 @@ describe Array do
|
|
522
523
|
[:a, :b, :c].includes?(5).should == false
|
523
524
|
end
|
524
525
|
|
526
|
+
it "rpads" do
|
527
|
+
[1,2,3].rpad(5).should == [1,2,3,nil,nil]
|
528
|
+
end
|
529
|
+
|
530
|
+
it "transpose_with_padding" do
|
531
|
+
a = [
|
532
|
+
[1,2],
|
533
|
+
[1],
|
534
|
+
[1,2,3]
|
535
|
+
]
|
536
|
+
|
537
|
+
a_transposed = [
|
538
|
+
[1,2,nil],
|
539
|
+
[1,nil,nil],
|
540
|
+
[1,2,3]
|
541
|
+
].transpose
|
542
|
+
|
543
|
+
a.transpose_with_padding.should == a_transposed
|
544
|
+
end
|
545
|
+
|
546
|
+
it "rows and columnses" do
|
547
|
+
a = [
|
548
|
+
[ 1, 2, 3, 4, 5 ],
|
549
|
+
[ 6, 7, 8, 9, 10 ],
|
550
|
+
[ 11, 12 ],
|
551
|
+
]
|
552
|
+
|
553
|
+
a.row(0).should == [1,2,3,4,5]
|
554
|
+
a.col(0).should == [1,6,11]
|
555
|
+
a.col(-1).should == [5,10]
|
556
|
+
a.col(-10).should == nil
|
557
|
+
|
558
|
+
a.cols.map(&:size).should == [3,3,2,2,2]
|
559
|
+
end
|
560
|
+
|
525
561
|
end
|
526
562
|
|
527
563
|
|
@@ -660,6 +696,11 @@ describe Enumerable do
|
|
660
696
|
(a * b).to_a.should == [[1,3],[1,4],[2,3],[2,4]]
|
661
697
|
end
|
662
698
|
|
699
|
+
it "rles" do
|
700
|
+
[1, 2, 3,3,3, 4].rle.to_a.should == [ [1,1], [1,2], [3,3], [1,4] ]
|
701
|
+
[5,5, 1, 2, 3,3,3, 4,4].rle.to_a.should == [ [2,5], [1,1], [1,2], [3,3], [2,4] ]
|
702
|
+
end
|
703
|
+
|
663
704
|
it "sorts strings numerically" do
|
664
705
|
a = ["a1", "a11", "a2", "a3"]
|
665
706
|
proper = ["a1", "a2", "a3", "a11"]
|
@@ -673,6 +714,7 @@ describe Enumerable do
|
|
673
714
|
|
674
715
|
end
|
675
716
|
|
717
|
+
|
676
718
|
describe Enumerator do
|
677
719
|
|
678
720
|
it "spins" do
|
@@ -831,6 +873,7 @@ describe Binding do
|
|
831
873
|
b.call.should == 5
|
832
874
|
end
|
833
875
|
|
876
|
+
|
834
877
|
describe Proc do
|
835
878
|
|
836
879
|
it "joins procs" do
|
data/spec/path_spec.rb
CHANGED
@@ -242,7 +242,7 @@ describe Path do
|
|
242
242
|
path.exists?.should == false
|
243
243
|
|
244
244
|
path.touch
|
245
|
-
lambda { path.rename(:ext=>".dat") }.should raise_error
|
245
|
+
lambda { path.rename(:ext=>".dat") }.should raise_error(RuntimeError)
|
246
246
|
|
247
247
|
dest.rm
|
248
248
|
path.rename!(:ext=>".dat")
|
@@ -264,7 +264,7 @@ describe Path do
|
|
264
264
|
dest.rm
|
265
265
|
|
266
266
|
path.touch
|
267
|
-
p path.numbered_backup_file
|
267
|
+
# p path.numbered_backup_file
|
268
268
|
|
269
269
|
dest = path.numbered_backup!
|
270
270
|
path.touch
|
@@ -275,6 +275,14 @@ describe Path do
|
|
275
275
|
|
276
276
|
dest.rm
|
277
277
|
dest2.rm
|
278
|
+
|
279
|
+
|
280
|
+
path = Path.tmpdir
|
281
|
+
path.dir?.should == true
|
282
|
+
backup = path.numbered_backup!
|
283
|
+
backup.dir?.should == true
|
284
|
+
backup.dirs.last.should == "#{path.dirs.last} (1)"
|
285
|
+
backup.rm
|
278
286
|
end
|
279
287
|
|
280
288
|
it "rms" do
|
@@ -316,7 +324,7 @@ describe Path do
|
|
316
324
|
|
317
325
|
it "mkdirs" do
|
318
326
|
tmp = Path.tmpfile
|
319
|
-
lambda { tmp.mkdir }.should raise_error
|
327
|
+
lambda { tmp.mkdir }.should raise_error(RuntimeError)
|
320
328
|
tmp.rm
|
321
329
|
tmp.mkdir.should be_truthy
|
322
330
|
tmp.rm.should be_truthy
|
@@ -409,7 +417,7 @@ describe Path do
|
|
409
417
|
end
|
410
418
|
|
411
419
|
it "modes" do
|
412
|
-
Path.tmpfile.mode.class.should ==
|
420
|
+
Path.tmpfile.mode.class.should == Integer
|
413
421
|
end
|
414
422
|
|
415
423
|
it "chmods and chmod_Rs" do
|
@@ -547,7 +555,7 @@ describe Path do
|
|
547
555
|
file["user.test"].should == nil
|
548
556
|
Path.getfattr(file)["user.test"].should == nil
|
549
557
|
|
550
|
-
lambda { file["blahblahblah"] = "whee" }.should raise_error
|
558
|
+
lambda { file["blahblahblah"] = "whee" }.should raise_error(RuntimeError)
|
551
559
|
|
552
560
|
# Test assigning an entire hash of attributes, using diffing
|
553
561
|
attrs = file.attrs
|
@@ -584,4 +592,12 @@ describe Path do
|
|
584
592
|
# if the source is a file, copies it and builds the directory tree
|
585
593
|
end
|
586
594
|
|
595
|
+
it "id3's" do
|
596
|
+
path = Path["test.mp3"]
|
597
|
+
if path.exists?
|
598
|
+
tags = path.id3
|
599
|
+
tags.title.should_not == nil
|
600
|
+
tags.artist.should_not == nil
|
601
|
+
end
|
602
|
+
end
|
587
603
|
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.112
|
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-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|