epitools 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,20 +1,13 @@
1
- Copyright (c) 2009 epitron
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
2
3
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
4
+ Copyright (C) 2004 Sam Hocevar
5
+ 14 rue de Plaisance, 75014 Paris, France
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
10
9
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
12
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
@@ -1,19 +1,21 @@
1
1
  = epitools
2
2
 
3
- There's some interesting stuff in here. Unfortunately, it's all gross and
4
- disorganized. This will change. :D
5
-
6
- == Note on Patches/Pull Requests
7
-
8
- * Fork the project.
9
- * Make your feature addition or bug fix.
10
- * Add tests for it. This is important so I don't break it in a
11
- future version unintentionally.
12
- * Commit, do not mess with rakefile, version, or history.
13
- (if you want to have your own version, that is fine but
14
- bump version in a commit by itself I can ignore when I pull)
15
- * Send me a pull request. Bonus points for topic branches.
3
+ Awesome collection of Ruby tools!
4
+
5
+ == Installing
6
+
7
+ gem install epitools
8
+
9
+ == Usage
10
+
11
+ This is basically a collection of enhancements to the ruby base types (Hash, Array,
12
+ Enumerable, etc.). To learn how it works, read the specs in spec/*.rb,
13
+ or check out the rdoc: http://rdoc.info/projects/epitron/epitools
16
14
 
17
15
  == Copyright
18
16
 
19
- Copyright (c) 2009 epitron. See LICENSE for details.
17
+ Copyright (c) 2009-2010 epitron
18
+
19
+ == License
20
+
21
+ Licensed under the WTFPL2. (See LICENSE for details.)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["epitron"]
12
- s.date = %q{2010-05-15}
12
+ s.date = %q{2010-05-16}
13
13
  s.description = %q{Miscellaneous utility libraries to make my life easier.}
14
14
  s.email = %q{chris@ill-logic.com}
15
15
  s.extra_rdoc_files = [
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  "lib/epitools/rash.rb",
38
38
  "lib/epitools/ratio.rb",
39
39
  "lib/epitools/string_to_proc.rb",
40
+ "lib/epitools/zopen.rb",
40
41
  "spec/basetypes_spec.rb",
41
42
  "spec/lcs_spec.rb",
42
43
  "spec/metaclass_spec.rb",
@@ -44,7 +45,8 @@ Gem::Specification.new do |s|
44
45
  "spec/rash_spec.rb",
45
46
  "spec/ratio_spec.rb",
46
47
  "spec/spec.opts",
47
- "spec/spec_helper.rb"
48
+ "spec/spec_helper.rb",
49
+ "spec/zopen_spec.rb"
48
50
  ]
49
51
  s.homepage = %q{http://github.com/epitron/epitools}
50
52
  s.rdoc_options = ["--charset=UTF-8"]
@@ -52,13 +54,14 @@ Gem::Specification.new do |s|
52
54
  s.rubygems_version = %q{1.3.6}
53
55
  s.summary = %q{NOT UTILS... METILS!}
54
56
  s.test_files = [
55
- "spec/permutations_spec.rb",
56
- "spec/rash_spec.rb",
57
- "spec/spec_helper.rb",
57
+ "spec/zopen_spec.rb",
58
58
  "spec/lcs_spec.rb",
59
- "spec/basetypes_spec.rb",
59
+ "spec/rash_spec.rb",
60
+ "spec/metaclass_spec.rb",
60
61
  "spec/ratio_spec.rb",
61
- "spec/metaclass_spec.rb"
62
+ "spec/permutations_spec.rb",
63
+ "spec/spec_helper.rb",
64
+ "spec/basetypes_spec.rb"
62
65
  ]
63
66
 
64
67
  if s.respond_to? :specification_version then
@@ -7,6 +7,7 @@ __DIR__ = File.dirname(__FILE__)
7
7
  string_to_proc
8
8
  permutations
9
9
  ratio
10
+ general
10
11
  ].each do |mod|
11
12
  require File.join(__DIR__, "epitools", mod)
12
13
  end
@@ -0,0 +1,30 @@
1
+ require 'zlib'
2
+
3
+ #
4
+ # A mutation of "open" that lets you read/write gzip files, as well as
5
+ # regular files. (NOTE: gzip detection is purely based on filename.)
6
+ #
7
+ def zopen(filename, mode="r")
8
+
9
+ file = open(filename, mode)
10
+
11
+ if filename =~ /\.gz$/
12
+ case mode
13
+ when "r"
14
+ file = Zlib::GzipReader.new(file)
15
+ when "w"
16
+ file = Zlib::GzipWriter.new(file)
17
+ else
18
+ raise "Unknown mode: #{mode.inspect}. zopen only supports 'r' and 'w'."
19
+ end
20
+ end
21
+
22
+ if block_given?
23
+ result = yield(file)
24
+ file.close
25
+ result
26
+ else
27
+ file
28
+ end
29
+
30
+ end
@@ -0,0 +1,49 @@
1
+ require 'epitools/zopen'
2
+ require 'tempfile'
3
+
4
+ describe "zopen()" do
5
+
6
+ before :all do
7
+ @data = ("x"*100+"\n") * 1000
8
+ @tmp = Tempfile.new("zopen_spec")
9
+
10
+ @plainfile = @tmp.path
11
+ @gzfile = "#{@tmp.path}.gz"
12
+ end
13
+
14
+ after :all do
15
+ File.unlink @plainfile
16
+ File.unlink @gzfile
17
+ end
18
+
19
+ it "writes/reads a gz" do
20
+ f = zopen(@gzfile, "w")
21
+ f.write(@data).should == @data.size
22
+ f.close
23
+
24
+ f = zopen(@gzfile, "r")
25
+ f.read.should == @data
26
+ f.close
27
+ end
28
+
29
+ it "writes/reads non-gz files" do
30
+ zopen(@plainfile, "w") {|f| f.write(@data) }
31
+
32
+ # readstyle
33
+ File.read(@plainfile).should == zopen(@plainfile).read
34
+
35
+ # blockstyle
36
+ open(@plainfile){|f| f.read }.should == zopen(@plainfile){|f| f.read }
37
+ end
38
+
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
+
45
+ f.all?{|line| line =~ /^x+$/ }
46
+ end
47
+ end
48
+
49
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - epitron
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-15 00:00:00 -04:00
17
+ date: 2010-05-16 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ files:
61
61
  - lib/epitools/rash.rb
62
62
  - lib/epitools/ratio.rb
63
63
  - lib/epitools/string_to_proc.rb
64
+ - lib/epitools/zopen.rb
64
65
  - spec/basetypes_spec.rb
65
66
  - spec/lcs_spec.rb
66
67
  - spec/metaclass_spec.rb
@@ -69,6 +70,7 @@ files:
69
70
  - spec/ratio_spec.rb
70
71
  - spec/spec.opts
71
72
  - spec/spec_helper.rb
73
+ - spec/zopen_spec.rb
72
74
  has_rdoc: true
73
75
  homepage: http://github.com/epitron/epitools
74
76
  licenses: []
@@ -100,10 +102,11 @@ signing_key:
100
102
  specification_version: 3
101
103
  summary: NOT UTILS... METILS!
102
104
  test_files:
103
- - spec/permutations_spec.rb
105
+ - spec/zopen_spec.rb
106
+ - spec/lcs_spec.rb
104
107
  - spec/rash_spec.rb
108
+ - spec/metaclass_spec.rb
109
+ - spec/ratio_spec.rb
110
+ - spec/permutations_spec.rb
105
111
  - spec/spec_helper.rb
106
- - spec/lcs_spec.rb
107
112
  - spec/basetypes_spec.rb
108
- - spec/ratio_spec.rb
109
- - spec/metaclass_spec.rb