Class: Stalkr::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/stalkr/base.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.regex ⇒ Object
Returns the value of attribute regex.
21
22
23
|
# File 'lib/stalkr/base.rb', line 21
def regex
@regex
end
|
Class Method Details
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/stalkr/base.rb', line 55
def self.(str)
r = regex()
if r.kind_of? Regexp then
r = [ r ]
end
r.each do |re|
if str =~ re then
m = $~.to_a
m.shift
return m.find{ |s| not s.nil? }.gsub(/ /, '').upcase
end
end
return nil
end
|
.is_valid?(id) ⇒ Boolean
51
52
53
|
# File 'lib/stalkr/base.rb', line 51
def self.is_valid?(id)
return (id =~ regex() ? true : false)
end
|
Instance Method Details
#cleanup_html(str) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/stalkr/base.rb', line 43
def cleanup_html(str)
str.gsub!(/ /, ' ')
str = strip_tags(str)
str.strip!
str.squeeze!(" \n\r")
return str
end
|
#fetchurl(url, data = nil) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/stalkr/base.rb', line 24
def fetchurl(url, data = nil)
if data.nil? then
return Curl::Easy.perform(url).body_str
else
return Curl::Easy.http_post(url, data.map{ |k,v| Curl::PostField.content(k, v) }).body_str
end
end
|
34
35
36
37
38
39
40
41
|
# File 'lib/stalkr/base.rb', line 34
def strip_tags(html)
HTMLEntities.new.decode(
html.gsub(/<.+?>/,'').
gsub(/<br *\/>/m, '')
)
end
|