epitools 0.5.107 → 0.5.108
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/autoloads.rb +7 -1
- data/lib/epitools/core_ext/file.rb +14 -0
- data/lib/epitools/core_ext/string.rb +24 -10
- data/lib/epitools/path.rb +41 -1
- data/lib/epitools/term.rb +2 -1
- data/spec/core_ext_spec.rb +14 -4
- data/spec/path_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab9478f3d24652d2ca54b4768f24905054ff7cf
|
4
|
+
data.tar.gz: 867cc04fd03832c71c8bca9564dd5601b7202d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b08b663ff1e86dc4386c3e9dbb95d4a9251720a3cd4b24b10d82a0329a6128489604f50da8524b85e3a1a9ba3e6a36aa45b0e914986b95516cc7052aa2410c26
|
7
|
+
data.tar.gz: c1e79ee112929443eeee1985c8fe24364a1981c3fce569135c141b4dc907c80dd5d0fad94692d16ca360a047abc38d20721f1a37f710e61b42bad80f5ce0b543
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.108
|
data/lib/epitools/autoloads.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
autoload :Set, 'set'
|
4
4
|
autoload :URI, 'uri'
|
5
|
-
autoload :CGI, 'cgi'
|
6
5
|
autoload :Zlib, 'zlib'
|
7
6
|
autoload :FileUtils, 'fileutils'
|
8
7
|
autoload :Tempfile, 'tempfile'
|
@@ -95,6 +94,13 @@ autoreq :AwesomePrint do
|
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
97
|
+
autoreq :CGI do
|
98
|
+
require 'cgi'
|
99
|
+
|
100
|
+
class CGI
|
101
|
+
@@accept_charset = "UTF-8" unless defined? @@accept_charset
|
102
|
+
end
|
103
|
+
end
|
98
104
|
|
99
105
|
## YAML hacks (the module might not be loaded properly in older Rubies)
|
100
106
|
|
@@ -143,4 +143,18 @@ class File
|
|
143
143
|
end
|
144
144
|
alias_method :reverse_seek_to, :seek_backwards_to
|
145
145
|
|
146
|
+
#
|
147
|
+
# Iterate over each line of the file, yielding the line and the byte offset of the start of the line in the file
|
148
|
+
#
|
149
|
+
def each_line_with_offset
|
150
|
+
return to_enum(:each_line_with_offset) unless block_given?
|
151
|
+
|
152
|
+
offset = 0
|
153
|
+
|
154
|
+
each_line do |line|
|
155
|
+
yield line, offset
|
156
|
+
offset = tell
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
146
160
|
end
|
@@ -4,6 +4,16 @@ require 'epitools/core_ext/numbers'
|
|
4
4
|
|
5
5
|
class String
|
6
6
|
|
7
|
+
#
|
8
|
+
# For `titlecase`
|
9
|
+
#
|
10
|
+
LOWERCASE_WORDS = Set.new %w[of to or the and an a at is for from in]
|
11
|
+
|
12
|
+
#
|
13
|
+
# For `words_without_stopwords`
|
14
|
+
#
|
15
|
+
STOP_WORDS = %w[a cannot into our thus about co is ours to above could it ourselves together across down its out too after during itself over toward afterwards each last own towards again eg latter per under against either latterly perhaps until all else least rather up almost elsewhere less same upon alone enough ltd seem us along etc many seemed very already even may seeming via also ever me seems was although every meanwhile several we always everyone might she well among everything more should were amongst everywhere moreover since what an except most so whatever and few mostly some when another first much somehow whence any for must someone whenever anyhow former my something where anyone formerly myself sometime whereafter anything from namely sometimes whereas anywhere further neither somewhere whereby are had never still wherein around has nevertheless such whereupon as have next than wherever at he no that whether be hence nobody the whither became her none their which because here noone them while become hereafter nor themselves who becomes hereby not then whoever becoming herein nothing thence whole been hereupon now there whom before hers nowhere thereafter whose beforehand herself of thereby why behind him off therefore will being himself often therein with below his on thereupon within beside how once these without besides however one they would between i only this yet beyond ie onto those you both if or though your but in other through yours by inc others throughout yourself can indeed otherwise thru yourselves]
|
16
|
+
|
7
17
|
#
|
8
18
|
# Convert \r\n to \n
|
9
19
|
#
|
@@ -25,11 +35,6 @@ class String
|
|
25
35
|
gsub(/\s+/,' ').strip
|
26
36
|
end
|
27
37
|
|
28
|
-
#
|
29
|
-
# For `titlecase`
|
30
|
-
#
|
31
|
-
LOWERCASE_WORDS = Set.new %w[of to or the and an a at is for from in]
|
32
|
-
|
33
38
|
#
|
34
39
|
# Return a new string converted to "Title Case" (first letter of each word capitalized)
|
35
40
|
#
|
@@ -129,13 +134,12 @@ class String
|
|
129
134
|
#
|
130
135
|
def wrap(width=nil)
|
131
136
|
if width.nil? or width < 0
|
132
|
-
|
133
|
-
_, winwidth = STDIN.winsize
|
137
|
+
term_width, _ = Term.size
|
134
138
|
|
135
|
-
if width < 0
|
136
|
-
width = (
|
139
|
+
if width and width < 0
|
140
|
+
width = (term_width - 1) + width
|
137
141
|
else
|
138
|
-
width =
|
142
|
+
width = term_width - 1
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
@@ -188,6 +192,16 @@ class String
|
|
188
192
|
end
|
189
193
|
alias_method :wrapdent, :wrap_and_indent
|
190
194
|
|
195
|
+
def words
|
196
|
+
scan /\w+/
|
197
|
+
# scan /^[a-z]+$|^\w+\-\w+|^[a-z]+[0-9]+[a-z]+$|^[0-9]+[a-z]+|^[a-z]+[0-9]+$/
|
198
|
+
end
|
199
|
+
|
200
|
+
def words_without_stopwords
|
201
|
+
downcase.words - STOP_WORDS
|
202
|
+
end
|
203
|
+
alias_method :without_stopwords, :words_without_stopwords
|
204
|
+
|
191
205
|
#
|
192
206
|
# Iterate over slices of the string of size `slice_width`.
|
193
207
|
#
|
data/lib/epitools/path.rb
CHANGED
@@ -658,6 +658,7 @@ class Path
|
|
658
658
|
def nicelines
|
659
659
|
lines.map(&:chomp)
|
660
660
|
end
|
661
|
+
alias_method :nice_lines, :nicelines
|
661
662
|
|
662
663
|
def unmarshal
|
663
664
|
read.unmarshal
|
@@ -666,7 +667,7 @@ class Path
|
|
666
667
|
def ls
|
667
668
|
Dir.foreach(path).
|
668
669
|
reject {|fn| fn == "." or fn == ".." }.
|
669
|
-
|
670
|
+
flat_map {|fn| self / fn }
|
670
671
|
end
|
671
672
|
|
672
673
|
def ls_r(symlinks=false)
|
@@ -980,6 +981,20 @@ class Path
|
|
980
981
|
dest
|
981
982
|
end
|
982
983
|
|
984
|
+
#
|
985
|
+
# Copy a file to a destination, creating all intermediate directories if they don't already exist
|
986
|
+
#
|
987
|
+
def cp_p(dest)
|
988
|
+
FileUtils.mkdir_p(dest.dir) unless File.directory? dest.dir
|
989
|
+
if file?
|
990
|
+
FileUtils.cp(path, dest)
|
991
|
+
elsif dir?
|
992
|
+
FileUtils.cp_r(path, dest)
|
993
|
+
end
|
994
|
+
|
995
|
+
dest
|
996
|
+
end
|
997
|
+
|
983
998
|
def cp(dest)
|
984
999
|
FileUtils.cp(path, dest)
|
985
1000
|
dest
|
@@ -997,6 +1012,31 @@ class Path
|
|
997
1012
|
|
998
1013
|
## Owners and permissions
|
999
1014
|
|
1015
|
+
#
|
1016
|
+
# Same usage as `FileUtils.chmod` (because it just calls `FileUtils.chmod`)
|
1017
|
+
#
|
1018
|
+
# eg:
|
1019
|
+
# path.chmod(0600) # mode bits in octal (can also be 0o600 in ruby)
|
1020
|
+
# path.chmod "u=wrx,go=rx", 'somecommand'
|
1021
|
+
# path.chmod "u=wr,go=rr", "my.rb", "your.rb", "his.rb", "her.rb"
|
1022
|
+
# path.chmod "ugo=rwx", "slutfile"
|
1023
|
+
# path.chmod "u=wrx,g=rx,o=rx", '/usr/bin/ruby', :verbose => true
|
1024
|
+
#
|
1025
|
+
# Letter things:
|
1026
|
+
# "a" :: is user, group, other mask.
|
1027
|
+
# "u" :: is user's mask.
|
1028
|
+
# "g" :: is group's mask.
|
1029
|
+
# "o" :: is other's mask.
|
1030
|
+
# "w" :: is write permission.
|
1031
|
+
# "r" :: is read permission.
|
1032
|
+
# "x" :: is execute permission.
|
1033
|
+
# "X" :: is execute permission for directories only, must be used in conjunction with "+"
|
1034
|
+
# "s" :: is uid, gid.
|
1035
|
+
# "t" :: is sticky bit.
|
1036
|
+
# "+" :: is added to a class given the specified mode.
|
1037
|
+
# "-" :: Is removed from a given class given mode.
|
1038
|
+
# "=" :: Is the exact nature of the class will be given a specified mode.
|
1039
|
+
#
|
1000
1040
|
def chmod(mode)
|
1001
1041
|
FileUtils.chmod(mode, self)
|
1002
1042
|
self
|
data/lib/epitools/term.rb
CHANGED
@@ -29,7 +29,7 @@ module Term
|
|
29
29
|
# Return the [width,height] of the terminal.
|
30
30
|
#
|
31
31
|
def size
|
32
|
-
|
32
|
+
$stdout.winsize.reverse
|
33
33
|
end
|
34
34
|
|
35
35
|
def width; size[0]; end
|
@@ -140,6 +140,7 @@ module Term
|
|
140
140
|
render sliced_into(num_rows).transpose
|
141
141
|
end
|
142
142
|
alias_method :by_columns, :in_columns
|
143
|
+
alias_method :by_cols, :in_columns
|
143
144
|
|
144
145
|
def in_rows
|
145
146
|
return '' if @data.empty?
|
data/spec/core_ext_spec.rb
CHANGED
@@ -298,17 +298,27 @@ describe String do
|
|
298
298
|
s.deflate(9).size.should < s.deflate(0).size
|
299
299
|
end
|
300
300
|
|
301
|
+
it "wordses" do
|
302
|
+
s = "This, is a bunch, of words."
|
303
|
+
s.words.should == ["This", "is", "a", "bunch", "of", "words"]
|
304
|
+
end
|
305
|
+
|
306
|
+
it "wordses without stopwords" do
|
307
|
+
s = "The answer to the ultimate question of life, the universe, and everything.".downcase
|
308
|
+
s.without_stopwords.should == ["answer", "ultimate", "question", "life", "universe"]
|
309
|
+
end
|
310
|
+
|
301
311
|
it "starts/endswith" do
|
302
312
|
"blahblahblah".startswith("blah").should == true
|
303
313
|
"blahblahblah".endswith("blah").should == true
|
304
314
|
end
|
305
315
|
|
306
316
|
it "amounts" do
|
307
|
-
|
308
|
-
|
309
|
-
|
317
|
+
"cookie".amount(5).should == "5 cookies"
|
318
|
+
"cookie".amount(0).should == "0 cookies"
|
319
|
+
"shirt".amount(17).should == "17 shirts"
|
310
320
|
"dollar".amount(-10).should == "-10 dollars"
|
311
|
-
|
321
|
+
"love".amount(1).should == "1 love"
|
312
322
|
end
|
313
323
|
|
314
324
|
it "slices" do
|
data/spec/path_spec.rb
CHANGED
@@ -578,4 +578,10 @@ describe Path do
|
|
578
578
|
path.each_chunk(20) { |chunk| chunk.size.should == 20; break }
|
579
579
|
end
|
580
580
|
|
581
|
+
it "cp_p's" do
|
582
|
+
# raises an exception if one of the path components is an existing file (mkdir_p will fail!)
|
583
|
+
# if the source is a directory, copies it recursively
|
584
|
+
# if the source is a file, copies it and builds the directory tree
|
585
|
+
end
|
586
|
+
|
581
587
|
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.108
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|