epitools 0.4.49 → 0.5.0

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.
@@ -14,8 +14,8 @@ require 'epitools'
14
14
  # zopen("otherfile.gz", "w") #=> #<Zlib::GzipWriter:0x7fe30448>>
15
15
  # zopen("test.txt.gz") { |f| f.read } # read the contents of the .gz file, then close the file handle automatically.
16
16
  #
17
- def zopen(path, mode="r")
18
-
17
+ def zopen(path, mode="rb")
18
+
19
19
  path = Path[path] unless path.is_a? Path
20
20
  file = path.open(mode)
21
21
 
@@ -85,6 +85,12 @@ describe Object do
85
85
  end.should_not raise_error
86
86
 
87
87
  end
88
+
89
+ it "marshals/unmarshals" do
90
+ :whee.marshal.unmarshal.should == :whee
91
+ :whee.marshal.should == Marshal.dump(:whee)
92
+ end
93
+
88
94
 
89
95
  end
90
96
 
@@ -135,7 +141,7 @@ describe Numeric do
135
141
  1.year.ago.year.should == Time.now.year - 1
136
142
  5.days.from_now.to_i.should == (Time.now + 5.days).to_i
137
143
  end
138
-
144
+
139
145
  end
140
146
 
141
147
 
@@ -159,6 +165,12 @@ describe String do
159
165
  "\n\n\nblah\n\n\nblah\n\n\n".nice_lines.should == ["blah", "blah"]
160
166
  end
161
167
 
168
+ it "strips color" do
169
+ s = "woot!"
170
+ color_s = s.light_green
171
+ color_s.strip_color.should == s
172
+ end
173
+
162
174
  it "urlencodes/decodes" do
163
175
  s = "hi + there & mom + !!!!! I AM ON RSPEC"
164
176
  s.urlencode.should_not == s
@@ -193,7 +205,7 @@ describe String do
193
205
  "blahblahblah".startswith("blah").should == true
194
206
  "blahblahblah".endswith("blah").should == true
195
207
  end
196
-
208
+
197
209
  end
198
210
 
199
211
 
@@ -215,6 +227,12 @@ describe Integer do
215
227
  2.to_bits.should == [0,1]
216
228
  3.to_bits.should == [1,1]
217
229
  42.to_bits.should == [0,1,0,1,0,1]
230
+
231
+ # round trip
232
+ 20.times do
233
+ n = rand(918282393982)
234
+ n.to_bits.reverse.join.to_i(2).should == n
235
+ end
218
236
  end
219
237
 
220
238
  it "slices into bits" do
@@ -229,6 +247,17 @@ describe Integer do
229
247
  i[-3..-1].should == [1,1,1]
230
248
  i[0..-1].should == [1,1,0,1,1,1]
231
249
  end
250
+
251
+ it "converts to/from base62" do
252
+ Integer::BASE62_BASE.should == 62
253
+
254
+ [1,20,500,501,34191923].each do |n|
255
+ n.to_base62.from_base62.should == n
256
+ end
257
+
258
+ sum = "asdf".md5
259
+ sum.to_base62.from_base62.to_s(16).should == sum
260
+ end
232
261
 
233
262
  end
234
263
 
@@ -259,6 +288,17 @@ describe Array do
259
288
  a.middle.should == 3
260
289
  end
261
290
 
291
+ it "/'s" do
292
+ a = [1,2,3,4,5]
293
+ b = [1,2,3,4]
294
+
295
+ # splits?
296
+ (a/2).should == [[1,2,3],[4,5]]
297
+ (a/3).should == [[1,2],[3,4],[5]]
298
+
299
+ (b/2).should == [[1,2],[3,4]]
300
+ end
301
+
262
302
  end
263
303
 
264
304
 
@@ -0,0 +1,47 @@
1
+ require 'epitools/ezdb'
2
+ require 'epitools/path'
3
+
4
+ class Test < Struct.new(:a, :b); end
5
+
6
+ describe Ezdb do
7
+
8
+ attr_accessor :db
9
+
10
+ before :each do
11
+ @dbfile = Path["test.db"]
12
+ @dbfile.rm if @dbfile.exists?
13
+ @db = Ezdb.new @dbfile
14
+ end
15
+
16
+ after :each do
17
+ @db.delete!
18
+ end
19
+
20
+ it "stores/retrieves" do
21
+ db[1].should == nil
22
+ db[1] = :blah
23
+ db[1].should == :blah
24
+ db.keys.should == [1]
25
+
26
+ s = Test.new("what", true)
27
+ db[s] = false
28
+ db[s].should == false
29
+ end
30
+
31
+ it "handles nil extensions" do
32
+ x = Ezdb.new "testdb"
33
+ x[1].should == nil
34
+ x.delete!
35
+ end
36
+
37
+ it "pushes" do
38
+ db[:a] ||= []
39
+ db[:a].should == []
40
+ db[:a] << 1
41
+ db[:a] << 2
42
+ db[:a] << 3
43
+ db[:a] << 4
44
+ db[:a].should == [1,2,3,4]
45
+ end
46
+
47
+ end
@@ -147,7 +147,7 @@ describe Path do
147
147
 
148
148
  path.write "blah"
149
149
  path.append "what"
150
- path << "lul"
150
+ (path << "lul").should == path
151
151
 
152
152
  path.read.should == "blahwhatlul"
153
153
 
@@ -204,8 +204,8 @@ describe Path do
204
204
  tmp = Path.tmpfile
205
205
  lambda { tmp.mkdir }.should raise_error
206
206
  tmp.rm
207
- tmp.mkdir.should == true
208
- tmp.rm.should == true
207
+ tmp.mkdir.should be_truthy
208
+ tmp.rm.should be_truthy
209
209
  end
210
210
 
211
211
  it "has classmethods" do
@@ -256,6 +256,8 @@ describe Path do
256
256
  it "whiches" do
257
257
  Path.which("ruby").should_not be_nil
258
258
  Path.which("asdfasdfhkajlsdhfkljashdf").should be_nil
259
+ Path.which("ruby").class.should == Path
260
+ Path.which("gzip", "ls", "rm").should == ["/bin/gzip", "/bin/ls", "/bin/rm"]
259
261
  end
260
262
 
261
263
  it "Path[]s another path" do
@@ -275,4 +277,48 @@ describe Path do
275
277
 
276
278
  end
277
279
 
280
+ it "modes" do
281
+ Path.tmpfile.mode.class.should == Fixnum
282
+ end
283
+
284
+ it "chmods and chmod_Rs" do
285
+ tmp = Path.tmpfile
286
+ tmp2 = Path.tmpfile
287
+ tmp.touch
288
+ tmp2.touch
289
+
290
+ newmode = tmp.mode
291
+ tmp.chmod("+x")
292
+ system("chmod", "+x", tmp2)
293
+ tmp.mode.should == tmp2.mode
294
+ end
295
+
296
+ it "siblingses" do
297
+ sibs = Path.tempfile.siblings
298
+ sibs.is_an?(Array).should == true
299
+ sibs.include?(self).should == false
300
+ end
301
+
302
+ it 'path/".."s shows parent dir of file' do
303
+ # path/
304
+ tmp = Path.tmpfile
305
+ tmp.rm if tmp.exists?
306
+ tmp.mkdir
307
+ p tmp
308
+ p tmp.dirs
309
+ #tmp.to_s.endswith('/').should == true
310
+ file = tmp/"file"
311
+ file.touch
312
+ p file
313
+ file.dirs.should == tmp.dirs
314
+ file.filename.should != tmp.filename
315
+ end
316
+
317
+ it 'swaps two files' do
318
+ raise "errorn!"
319
+ # swap two regular files
320
+ # swap a symlink and a regular file
321
+ # swap two symlinks
322
+ end
323
+
278
324
  end
@@ -11,7 +11,7 @@ describe Rash do
11
11
  "other" => "whee",
12
12
  true => false,
13
13
  1 => "awesome"
14
- # /.+/ => "EVERYTHING"
14
+ #/.+/ => "EVERYTHING"
15
15
  )
16
16
  end
17
17
 
@@ -0,0 +1,35 @@
1
+ require 'epitools/term'
2
+
3
+ describe Term do
4
+
5
+ it "sizes" do
6
+ width, height = Term.size
7
+ width.class.should == Fixnum
8
+ height.class.should == Fixnum
9
+ end
10
+
11
+ it "tables" do
12
+ table = Term::Table[ (1..1000).to_a ]
13
+ #p [:cols, table.num_columns]
14
+ #p [:rows, table.num_rows]
15
+ #puts "columns"
16
+ #puts table.by_columns :border=>true
17
+ #puts "rows"
18
+ #puts table.by_rows
19
+ table.by_columns.should_not be_nil
20
+ table.by_rows.should_not be_nil
21
+
22
+ table.border = true
23
+
24
+ table.by_columns.should_not be_nil
25
+ table.by_rows.should_not be_nil
26
+ end
27
+
28
+ it "tables nothing" do
29
+ table = Term::Table.new []
30
+ lambda { table.by_rows }.should_not raise_error
31
+ lambda { table.by_columns }.should_not raise_error
32
+ end
33
+
34
+ end
35
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.49
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-29 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-10-13 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
- requirement: &75824280 !ruby/object:Gem::Requirement
16
+ requirement: &71901040 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 2.2.0
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *75824280
24
+ version_requirements: *71901040
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: mechanize
28
- requirement: &75824040 !ruby/object:Gem::Requirement
27
+ requirement: &71900430 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 1.0.0
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *75824040
35
+ version_requirements: *71900430
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: sqlite3-ruby
39
- requirement: &75823750 !ruby/object:Gem::Requirement
38
+ requirement: &71899880 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,7 +43,7 @@ dependencies:
44
43
  version: '0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *75823750
46
+ version_requirements: *71899880
48
47
  description: Miscellaneous utility libraries to make my life easier.
49
48
  email: chris@ill-logic.com
50
49
  executables: []
@@ -52,11 +51,13 @@ extensions: []
52
51
  extra_rdoc_files:
53
52
  - LICENSE
54
53
  - README.rdoc
54
+ - TODO
55
55
  files:
56
56
  - .document
57
57
  - LICENSE
58
58
  - README.rdoc
59
59
  - Rakefile
60
+ - TODO
60
61
  - VERSION
61
62
  - epitools.gemspec
62
63
  - lib/epitools.rb
@@ -67,6 +68,7 @@ files:
67
68
  - lib/epitools/browser/mechanize_progressbar.rb
68
69
  - lib/epitools/clitools.rb
69
70
  - lib/epitools/colored.rb
71
+ - lib/epitools/ezdb.rb
70
72
  - lib/epitools/hexdump.rb
71
73
  - lib/epitools/its.rb
72
74
  - lib/epitools/lcs.rb
@@ -83,12 +85,15 @@ files:
83
85
  - lib/epitools/ratio.rb
84
86
  - lib/epitools/string_to_proc.rb
85
87
  - lib/epitools/sys.rb
88
+ - lib/epitools/term.rb
89
+ - lib/epitools/trie.rb
86
90
  - lib/epitools/zopen.rb
87
91
  - spec/autoreq_spec.rb
88
92
  - spec/basetypes_spec.rb
89
93
  - spec/browser_spec.rb
90
94
  - spec/clitools_spec.rb
91
95
  - spec/colored_spec.rb
96
+ - spec/ezdb_spec.rb
92
97
  - spec/lcs_spec.rb
93
98
  - spec/numwords_spec.rb
94
99
  - spec/path_spec.rb
@@ -98,8 +103,8 @@ files:
98
103
  - spec/spec.opts
99
104
  - spec/spec_helper.rb
100
105
  - spec/sys_spec.rb
106
+ - spec/term_spec.rb
101
107
  - spec/zopen_spec.rb
102
- has_rdoc: true
103
108
  homepage: http://github.com/epitron/epitools
104
109
  licenses:
105
110
  - WTFPL
@@ -121,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
126
  version: '0'
122
127
  requirements: []
123
128
  rubyforge_project:
124
- rubygems_version: 1.6.2
129
+ rubygems_version: 1.8.6
125
130
  signing_key:
126
131
  specification_version: 3
127
132
  summary: NOT UTILS... METILS!