epitools 0.4.14 → 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,11 +6,12 @@ data structures and handy wrappers.
6
6
  Base classess: Object, Enumerable, Hash, String, Array, Integer, etc.
7
7
 
8
8
  Extras:
9
- * Path (a better Pathname)
10
- * Rash (a hash which can have Regexps as keys, allowing a single (key,value) pair to match many keys.)
11
- * Progressbar (better than the progressbar gem)
12
- * Colored (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
13
- * Browser (a fake browser, using mechanize, Progressbar, and CacheDB)
9
+
10
+ * Path (a better Pathname)
11
+ * Rash (a hash which can have Regexps as keys, allowing a single (key,value) pair to match many keys.)
12
+ * Progressbar (better than the progressbar gem)
13
+ * Colored (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
14
+ * Browser (a fake browser, using mechanize, Progressbar, and CacheDB)
14
15
 
15
16
  == Installing
16
17
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.14
1
+ 0.4.15
data/epitools.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.4.14"
8
+ s.version = "0.4.15"
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{2011-03-01}
12
+ s.date = %q{2011-03-14}
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 = [
@@ -98,7 +98,7 @@ class Integer
98
98
  end
99
99
 
100
100
  #
101
- # Convert the number to an array of bits (least significant digit first).
101
+ # Convert the number to an array of bits (least significant digit first, or little-endian).
102
102
  #
103
103
  def to_bits
104
104
  ("%b" % self).chars.to_a.reverse.map(&:to_i)
@@ -109,6 +109,35 @@ class Integer
109
109
  end
110
110
 
111
111
 
112
+ #
113
+ # Monkeypatch [] into Bignum and Fixnum using class_eval.
114
+ #
115
+ # (This is necessary because [] is defined directly on the classes, and a mixin
116
+ # module will still be overridden by Big/Fixnum's native [] method.)
117
+ #
118
+ [Bignum, Fixnum].each do |klass|
119
+
120
+ klass.class_eval do
121
+
122
+ alias_method :bit, :[]
123
+
124
+ #
125
+ # Extends [] so that Integers can be sliced as if they were arrays.
126
+ #
127
+ def [](arg)
128
+ case arg
129
+ when Integer
130
+ bit(arg)
131
+ when Range
132
+ bits[arg]
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+
112
141
  class Array
113
142
 
114
143
  def blank?; not self.any?; end
data/lib/epitools/path.rb CHANGED
@@ -158,5 +158,19 @@ class Path
158
158
  def <=>(other)
159
159
  self.path <=> other.path
160
160
  end
161
+
162
+ ## opening/reading
163
+
164
+ def open(mode="rb", &block)
165
+ if block_given?
166
+ File.open(path, mode, &block)
167
+ else
168
+ File.open(path, mode)
169
+ end
170
+ end
171
+
172
+ def read(length=nil, offset=nil)
173
+ File.read(path, length, offset)
174
+ end
161
175
 
162
176
  end
@@ -115,6 +115,20 @@ describe Integer do
115
115
  42.to_bits.should == [0,1,0,1,0,1]
116
116
  end
117
117
 
118
+ it "slices into bits" do
119
+ i = "111011".to_i(2)
120
+ # Note: to_i(2) accepts big-endian, while the Fixnum#[] slicing will return little endian.
121
+ # So make sure to reverse the bit string for the specs.
122
+
123
+ i[0].should == 1
124
+ i[2].should == 0
125
+
126
+ i[0..2].should == [1,1,0]
127
+ i[-3..-1].should == [1,1,1]
128
+ i[0..-1].should == [1,1,0,1,1,1]
129
+
130
+ end
131
+
118
132
  end
119
133
 
120
134
 
data/spec/path_spec.rb CHANGED
@@ -74,14 +74,31 @@ describe Path do
74
74
  Path[glob].should == specs
75
75
  end
76
76
 
77
- it "String#to_paths" do
78
- __FILE__.to_path.should == Path.new(__FILE__)
77
+ it "paths can be passed to ruby File methods" do
78
+ path = Path.new(__FILE__)
79
+ data = File.read(path)
80
+ data.size.should > 0
79
81
  end
80
82
 
81
- it "to_strs" do
83
+ it "opens & read files" do
82
84
  path = Path.new(__FILE__)
83
- data = File.read(path)
84
- data.any?.should == true
85
+
86
+ path.open do |f|
87
+ f.read.size.should > 0
88
+ end
89
+
90
+ path.read.size.should > 0
91
+ end
92
+
93
+ it "reads with length and offset" do
94
+ path = Path.new(__FILE__)
95
+
96
+ path.read(25).size.should == 25
97
+
98
+ s1 = path.read(25,15)
99
+ s2 = path.read(40)
100
+
101
+ s2[15..-1].should == s1
85
102
  end
86
103
 
87
104
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.14
5
+ version: 0.4.15
6
6
  platform: ruby
7
7
  authors:
8
8
  - epitron
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 -05:00
13
+ date: 2011-03-14 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency