kabutops 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/kabutops/crawler.rb +9 -0
- data/lib/kabutops/recipe.rb +2 -2
- data/lib/kabutops/recipe_item.rb +21 -3
- data/lib/kabutops/version.rb +1 -1
- 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: 2079759508e14efc73da0711fefa3bafa7e2cffa
|
4
|
+
data.tar.gz: 0034b70dbeca4dafd3471125f47392a4c7e98693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5315b48bff4207c58ff56242120cf6c9feb5297b29d668607241238ff9f1e0f01df16bf0ed45367b927690f6c55480b212761aec3dda0261a6af3ade1676e6b7
|
7
|
+
data.tar.gz: c00e64003cd9b3bb26685ed74dd16052e9b952cfa5e89baf0cf36f35d4d2cca77e3ee618c50d68f82d3e15aa2d239d45aebadea33b774ec507813ce15abfeb51
|
data/README.md
CHANGED
data/lib/kabutops/crawler.rb
CHANGED
@@ -75,6 +75,8 @@ module Kabutops
|
|
75
75
|
|
76
76
|
page = crawl(resource)
|
77
77
|
|
78
|
+
return if page.nil?
|
79
|
+
|
78
80
|
adapters.each do |adapter|
|
79
81
|
adapter.process(resource, page)
|
80
82
|
end
|
@@ -113,6 +115,13 @@ module Kabutops
|
|
113
115
|
page = Nokogiri::HTML(content) if page.nil?
|
114
116
|
self.class.notify(:after_crawl, resource, page)
|
115
117
|
page
|
118
|
+
rescue Mechanize::ResponseCodeError => e
|
119
|
+
if e.response_code.to_i == 404
|
120
|
+
nil
|
121
|
+
else
|
122
|
+
p e.response_code
|
123
|
+
raise
|
124
|
+
end
|
116
125
|
end
|
117
126
|
|
118
127
|
def agent
|
data/lib/kabutops/recipe.rb
CHANGED
@@ -17,8 +17,8 @@ module Kabutops
|
|
17
17
|
@items[name] = RecipeItem.new(:recipe, recipe)
|
18
18
|
@nested = true
|
19
19
|
else
|
20
|
-
type, value = args[0..
|
21
|
-
@items[name] = RecipeItem.new(type, value)
|
20
|
+
type, value, convert_to = args[0..2]
|
21
|
+
@items[name] = RecipeItem.new(type, value, convert_to)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/lib/kabutops/recipe_item.rb
CHANGED
@@ -5,27 +5,45 @@ module Kabutops
|
|
5
5
|
class RecipeItem
|
6
6
|
attr_reader :type, :value
|
7
7
|
|
8
|
-
def initialize type, value
|
8
|
+
def initialize type, value, convert_to=nil
|
9
9
|
@type = type
|
10
10
|
@value = value
|
11
|
+
@convert_to = convert_to
|
11
12
|
end
|
12
13
|
|
13
14
|
def process resource, page
|
15
|
+
convert(get(resource, page))
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def get resource, page
|
14
21
|
case @type
|
15
22
|
when :var
|
16
23
|
resource[@value]
|
17
24
|
when :recipe
|
18
25
|
@value.process(resource, page)
|
19
26
|
when :css
|
20
|
-
page.css(@value).text
|
27
|
+
page.css(@value).text.gsub(/\u00a0/, ' ').strip
|
21
28
|
when :xpath
|
22
|
-
page.xpath(@value).text
|
29
|
+
page.xpath(@value).text.gsub(/\u00a0/, ' ').strip
|
23
30
|
when :lambda, :proc
|
24
31
|
@value.call(resource, page)
|
25
32
|
else
|
26
33
|
raise "unknown recipe item type '#{item.type}'"
|
27
34
|
end
|
28
35
|
end
|
36
|
+
|
37
|
+
def convert v
|
38
|
+
return nil if v.nil?
|
39
|
+
|
40
|
+
case @convert_to
|
41
|
+
when nil then v
|
42
|
+
when :int then v[/\d+/].to_i
|
43
|
+
when :float then v[/\d+(\.\d+)?/].to_f
|
44
|
+
end
|
45
|
+
end
|
29
46
|
end
|
30
47
|
|
48
|
+
|
31
49
|
end
|
data/lib/kabutops/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kabutops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rene Klacan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|