epitools 0.5.61 → 0.5.63
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/browser.rb +4 -4
- data/lib/epitools/core_ext/string.rb +43 -29
- data/spec/core_ext_spec.rb +5 -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: 01cb576c29752c5f1213210a5fde6afbb21d2b24
|
|
4
|
+
data.tar.gz: cb4ef1ef088ffd7171cc2e4730a21e95d6d858d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1677a2683547b51b9d3f3808859e59a2c3282130d99f35b6d7e41b9d8d0cee4ce595af177305b3450400ca1aaeed1ab05ab6a69b58b7df347ce2e20a80ecfad8
|
|
7
|
+
data.tar.gz: 309c475a1afa44736c3e6c5baca3c458b4bd7c6d1d6762054b21d4c6a32683e7a0d1351aefe335eb563ffc04ae3566e46bb427669eaa6db4a2e8fcc4598007c7
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.63
|
data/lib/epitools/browser.rb
CHANGED
|
@@ -40,7 +40,7 @@ class Browser
|
|
|
40
40
|
@last_get = Time.at(0)
|
|
41
41
|
@delay = options[:delay] || 1
|
|
42
42
|
@delay_jitter = options[:delay_jitter] || 0.2
|
|
43
|
-
@use_cache = options[:cache]
|
|
43
|
+
@use_cache = !!(options[:cache] || options[:cached] || options[:use_cache])
|
|
44
44
|
@use_logs = options[:logs] || false
|
|
45
45
|
@cookie_file = options[:cookiefile] || "cookies.txt"
|
|
46
46
|
|
|
@@ -136,10 +136,10 @@ class Browser
|
|
|
136
136
|
# Determine the cache setting
|
|
137
137
|
use_cache = options[:cached].nil? ? @use_cache : options[:cached]
|
|
138
138
|
|
|
139
|
-
cached_already = cache.include?(url)
|
|
139
|
+
cached_already = cache.include?(url) if use_cache
|
|
140
140
|
|
|
141
141
|
puts
|
|
142
|
-
puts "[ GET #{url} (using cache: #{use_cache}) ]"
|
|
142
|
+
puts "[ GET #{url} (using cache: #{!!use_cache}) ]"
|
|
143
143
|
|
|
144
144
|
delay unless cached_already
|
|
145
145
|
max_retries = 4
|
|
@@ -152,7 +152,7 @@ class Browser
|
|
|
152
152
|
else
|
|
153
153
|
page = agent.get(url)
|
|
154
154
|
@last_get = Time.now
|
|
155
|
-
cache_put(page, url)
|
|
155
|
+
cache_put(page, url) if use_cache
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
puts
|
|
@@ -73,11 +73,26 @@ class String
|
|
|
73
73
|
dup.titlecase!
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
|
|
77
|
+
#
|
|
78
|
+
# A Regexp to recognize ANSI escape sequences
|
|
79
|
+
#
|
|
80
|
+
COLOR_REGEXP = /\e\[.*?(\d)+m/
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# This string contains ANSI (VT100) control codes
|
|
84
|
+
#
|
|
85
|
+
def contains_color?
|
|
86
|
+
self[COLOR_REGEXP]
|
|
87
|
+
end
|
|
88
|
+
alias_method :contains_colors?, :contains_color?
|
|
89
|
+
alias_method :contains_ansi?, :contains_color?
|
|
90
|
+
|
|
76
91
|
#
|
|
77
92
|
# Remove ANSI color codes.
|
|
78
93
|
#
|
|
79
94
|
def strip_color
|
|
80
|
-
gsub(
|
|
95
|
+
gsub(COLOR_REGEXP, '')
|
|
81
96
|
end
|
|
82
97
|
alias_method :strip_ansi, :strip_color
|
|
83
98
|
|
|
@@ -102,11 +117,34 @@ class String
|
|
|
102
117
|
alias_method :chomp_lines, :each_chomped
|
|
103
118
|
|
|
104
119
|
|
|
120
|
+
#
|
|
121
|
+
# Indent all the lines, if "prefix" is a string, prepend that string
|
|
122
|
+
# to each lien. If it's an integer, prepend that many spaces.
|
|
123
|
+
#
|
|
124
|
+
def indent(prefix=" ")
|
|
125
|
+
prefix = (" " * prefix) if prefix.is_an? Integer
|
|
126
|
+
|
|
127
|
+
if block_given?
|
|
128
|
+
lines.each { |line| yield prefix + line }
|
|
129
|
+
else
|
|
130
|
+
lines.map { |line| prefix + line }.join('')
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
#
|
|
135
|
+
# Use Nokogiri to parse this string as HTML, and return an indented version
|
|
136
|
+
#
|
|
137
|
+
def nice_html(indent=2)
|
|
138
|
+
Nokogiri::HTML.fragment(self).to_xhtml(indent: indent)
|
|
139
|
+
end
|
|
140
|
+
alias_method :nicehtml, :nice_html
|
|
141
|
+
alias_method :indent_html, :nice_html
|
|
142
|
+
|
|
105
143
|
#
|
|
106
144
|
# Wrap the lines in the string so they're at most "width" wide.
|
|
107
145
|
# (If no width is specified, defaults to the width of the terminal.)
|
|
108
146
|
#
|
|
109
|
-
def wrap(width=nil
|
|
147
|
+
def wrap(width=nil)
|
|
110
148
|
if width.nil? or width < 0
|
|
111
149
|
require 'io/console'
|
|
112
150
|
_, winwidth = STDIN.winsize
|
|
@@ -146,41 +184,17 @@ class String
|
|
|
146
184
|
end
|
|
147
185
|
end
|
|
148
186
|
|
|
149
|
-
#
|
|
150
|
-
# Indent all the lines, if "prefix" is a string, prepend that string
|
|
151
|
-
# to each lien. If it's an integer, prepend that many spaces.
|
|
152
|
-
#
|
|
153
|
-
def indent(prefix=" ")
|
|
154
|
-
prefix = (" " * prefix) if prefix.is_an? Integer
|
|
155
|
-
|
|
156
|
-
if block_given?
|
|
157
|
-
lines.each { |line| yield prefix + line }
|
|
158
|
-
else
|
|
159
|
-
lines.map { |line| prefix + line }.join('')
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
#
|
|
164
|
-
# Use Nokogiri to parse this string as HTML, and return an indented version
|
|
165
|
-
#
|
|
166
|
-
def nicehtml(indent=2)
|
|
167
|
-
Nokogiri::HTML(ARGF).to_xhtml(indent: indent)
|
|
168
|
-
end
|
|
169
|
-
alias_method :indent_html, :nicehtml
|
|
170
|
-
|
|
171
187
|
#
|
|
172
188
|
# Wrap all lines at window size, and indent
|
|
173
189
|
#
|
|
174
190
|
def wrapdent(prefix, width=nil)
|
|
175
|
-
prefix_size = prefix.strip_ansi.size
|
|
176
|
-
|
|
177
191
|
if width
|
|
178
|
-
width = width -
|
|
192
|
+
width = width - prefix.size
|
|
179
193
|
else
|
|
180
|
-
width = -
|
|
194
|
+
width = -prefix.size
|
|
181
195
|
end
|
|
182
196
|
|
|
183
|
-
wrap(width).map { |line|
|
|
197
|
+
wrap(width).each_line.map { |line| prefix + line }.join
|
|
184
198
|
end
|
|
185
199
|
|
|
186
200
|
#
|
data/spec/core_ext_spec.rb
CHANGED
|
@@ -223,6 +223,11 @@ describe String do
|
|
|
223
223
|
it "nice_lineses" do
|
|
224
224
|
"\n\n\nblah\n\n\nblah\n\n\n".nice_lines.should == ["blah", "blah"]
|
|
225
225
|
end
|
|
226
|
+
|
|
227
|
+
it "nice_htmls" do
|
|
228
|
+
s = "<a><b><p><c>whee</a>"
|
|
229
|
+
s.nice_html.should_not == s
|
|
230
|
+
end
|
|
226
231
|
|
|
227
232
|
it "wraps" do
|
|
228
233
|
s1 = "Hello there, I am a sentence or series of words."
|
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.63
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- epitron
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-12-
|
|
11
|
+
date: 2014-12-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|