epitools 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
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-12-05}
12
+ s.date = %q{2010-12-09}
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 = [
@@ -46,7 +46,6 @@ Gem::Specification.new do |s|
46
46
  "lib/epitools/zopen.rb",
47
47
  "spec/basetypes_spec.rb",
48
48
  "spec/browser_spec.rb",
49
- "spec/highlight_spec.rb",
50
49
  "spec/lcs_spec.rb",
51
50
  "spec/metaclass_spec.rb",
52
51
  "spec/permutations_spec.rb",
@@ -65,7 +64,7 @@ Gem::Specification.new do |s|
65
64
  s.test_files = [
66
65
  "spec/basetypes_spec.rb",
67
66
  "spec/browser_spec.rb",
68
- "spec/highlight_spec.rb",
67
+ "spec/clitools_spec.rb",
69
68
  "spec/lcs_spec.rb",
70
69
  "spec/metaclass_spec.rb",
71
70
  "spec/permutations_spec.rb",
@@ -16,8 +16,20 @@ class Object
16
16
  def integer?; false; end
17
17
  end
18
18
 
19
- class Float
19
+ class Numeric
20
20
  def integer?; true; end
21
+
22
+ def commatize
23
+ to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
24
+ end
25
+ end
26
+
27
+ class Float
28
+ def blank?; self == 0.0; end
29
+ end
30
+
31
+ class NilClass
32
+ def blank?; true; end
21
33
  end
22
34
 
23
35
  class String
@@ -26,9 +38,13 @@ class String
26
38
  # Could this string be cast to an integer?
27
39
  #
28
40
  def integer?
29
- self.strip.match(/^\d+$/) ? true : false
41
+ strip.match(/^\d+$/) ? true : false
30
42
  end
31
-
43
+
44
+ def blank?
45
+ strip.size == 0
46
+ end
47
+
32
48
  #
33
49
  # Convert \r\n to \n
34
50
  #
@@ -54,7 +70,7 @@ class String
54
70
  # Like #lines, but skips empty lines and removes \n's.
55
71
  #
56
72
  def nice_lines
57
- self.split("\n").map(&:strip).select(&:any?)
73
+ split("\n").select{|l| not l.blank? }
58
74
  end
59
75
 
60
76
  alias_method :clean_lines, :nice_lines
@@ -63,10 +79,8 @@ end
63
79
 
64
80
  class Integer
65
81
 
66
- def integer?
67
- true
68
- end
69
-
82
+ def blank?; self == 0; end
83
+
70
84
  def to_hex
71
85
  "%0.2x" % self
72
86
  end
@@ -84,7 +98,9 @@ end
84
98
 
85
99
 
86
100
  class Array
87
-
101
+
102
+ def blank?; not self.any?; end
103
+
88
104
  #
89
105
  # flatten.compact.uniq
90
106
  #
@@ -122,6 +138,10 @@ end
122
138
 
123
139
  module Enumerable
124
140
 
141
+ def blank?
142
+ not self.any?
143
+ end
144
+
125
145
  #
126
146
  # Split this enumerable into an array of pieces given some
127
147
  # boundary condition.
@@ -365,6 +385,10 @@ end
365
385
 
366
386
  class Hash
367
387
 
388
+ def blank?
389
+ not self.any?
390
+ end
391
+
368
392
  #
369
393
  # Runs remove_blank_lines on self.
370
394
  #
@@ -2,10 +2,12 @@ require 'mechanize'
2
2
  require 'uri'
3
3
  require 'fileutils'
4
4
 
5
+ require 'epitools/browser/browser_cache'
5
6
  require 'epitools/browser/mechanize_progressbar'
6
7
 
7
8
  # TODO: Make socksify optional (eg: if proxy is specified)
8
9
  #require 'socksify'
10
+ class SOCKSError < Exception; end
9
11
 
10
12
  # TODO: Put options here.
11
13
  =begin
@@ -98,7 +100,6 @@ class Browser
98
100
 
99
101
  def init_cache!
100
102
  # TODO: Rescue "couldn't load" exception and disable caching
101
- require 'epitools/browser/browser_cache'
102
103
  @cache = CacheDB.new(agent) if @use_cache
103
104
  end
104
105
 
@@ -133,27 +134,20 @@ class Browser
133
134
  #end
134
135
 
135
136
  # Determine the cache setting
136
- options[:use_cache] ||= @use_cache
137
-
138
- if options[:use_cache] == false
139
- options[:read_cache] = false
140
- options[:write_cache] = false
141
- end
142
-
143
- options[:read_cache] = true if options[:read_cache].nil?
144
- options[:write_cache] = true if options[:write_cache].nil?
145
137
 
146
- read_cache = options[:read_cache] && cache.include?(url)
147
- write_cache = options[:write_cache]
138
+
139
+ use_cache = options[:use_cache] || @use_cache
140
+
141
+ cached_already = cache.include?(url)
148
142
 
149
143
  puts
150
- puts "[ #{url.inspect} (read_cache=#{options[:read_cache]}, write_cache=#{options[:write_cache]}) ]"
144
+ puts "[ #{url.inspect} (use_cache=#{use_cache}) ]"
151
145
 
152
- delay unless read_cache
146
+ delay unless cached_already
153
147
 
154
148
  begin
155
149
 
156
- if read_cache
150
+ if cached_already
157
151
  page = cache.get(url)
158
152
  if page.nil?
159
153
  puts " |_ CACHE FAIL! Re-getting page."
@@ -165,7 +159,7 @@ class Browser
165
159
  @last_get = Time.now
166
160
  end
167
161
 
168
- cache_put(page, url) if write_cache and not read_cache
162
+ cache_put(page, url) unless cached_already
169
163
 
170
164
  puts
171
165
 
@@ -1,4 +1,4 @@
1
- #require 'mechanize'
1
+ require 'mechanize'
2
2
  require 'sqlite3'
3
3
 
4
4
  class CacheDB
@@ -28,10 +28,14 @@ class CacheDB
28
28
  alias_method :size, :count
29
29
 
30
30
  def put(page, original_url=nil, options={})
31
+ p [:put, original_url]
32
+
31
33
  raise "Invalid page" unless [:body, :content_type, :uri].all?{|m| page.respond_to? m }
32
34
 
33
35
  url = page.uri.to_s
34
36
 
37
+ p [:page_uri, url]
38
+
35
39
  if url != original_url
36
40
  # redirect original_url to url
37
41
  expire(original_url) if options[:overwrite]
@@ -69,7 +73,7 @@ class CacheDB
69
73
  else
70
74
  body = Zlib::Inflate.inflate(compressed_body)
71
75
 
72
- WWW::Mechanize::Page.new(
76
+ Mechanize::Page.new(
73
77
  URI.parse(url),
74
78
  {'content-type'=>content_type},
75
79
  body,
@@ -80,6 +84,7 @@ class CacheDB
80
84
  end
81
85
 
82
86
  def pages_via_sql(*args, &block)
87
+ p [:pages_via_sql, args]
83
88
  if block_given?
84
89
  db.execute(*args) do |row|
85
90
  yield row_to_page(row)
@@ -63,6 +63,17 @@ describe Object do
63
63
 
64
64
  end
65
65
 
66
+ describe Numeric do
67
+
68
+ it "commatizes" do
69
+ 123.commatize.should == "123"
70
+ 1234.commatize.should == "1,234"
71
+ 12983287123.commatize.should == "12,983,287,123"
72
+ -12983287123.commatize.should == "-12,983,287,123"
73
+ -12983287123.4411.commatize.should == "-12,983,287,123.4411"
74
+ end
75
+
76
+ end
66
77
 
67
78
  describe Integer do
68
79
 
@@ -1,4 +1,4 @@
1
- require 'epitools/highlight'
1
+ require 'epitools/clitools'
2
2
 
3
3
  describe String do
4
4
 
@@ -12,4 +12,4 @@ describe String do
12
12
  "xxxmatchzzz".highlight(/MATCH/i, color).should == highlighted
13
13
  end
14
14
 
15
- end
15
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
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-12-05 00:00:00 -05:00
17
+ date: 2010-12-09 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -99,7 +99,6 @@ files:
99
99
  - lib/epitools/zopen.rb
100
100
  - spec/basetypes_spec.rb
101
101
  - spec/browser_spec.rb
102
- - spec/highlight_spec.rb
103
102
  - spec/lcs_spec.rb
104
103
  - spec/metaclass_spec.rb
105
104
  - spec/permutations_spec.rb
@@ -109,6 +108,7 @@ files:
109
108
  - spec/spec_helper.rb
110
109
  - spec/sys_spec.rb
111
110
  - spec/zopen_spec.rb
111
+ - spec/clitools_spec.rb
112
112
  has_rdoc: true
113
113
  homepage: http://github.com/epitron/epitools
114
114
  licenses:
@@ -144,7 +144,7 @@ summary: NOT UTILS... METILS!
144
144
  test_files:
145
145
  - spec/basetypes_spec.rb
146
146
  - spec/browser_spec.rb
147
- - spec/highlight_spec.rb
147
+ - spec/clitools_spec.rb
148
148
  - spec/lcs_spec.rb
149
149
  - spec/metaclass_spec.rb
150
150
  - spec/permutations_spec.rb