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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b4f48640fb6de941353f09dee76176c4ce9ff07
4
- data.tar.gz: 41173f3f0826601540cdcd783da88c4c4dae9169
3
+ metadata.gz: 2079759508e14efc73da0711fefa3bafa7e2cffa
4
+ data.tar.gz: 0034b70dbeca4dafd3471125f47392a4c7e98693
5
5
  SHA512:
6
- metadata.gz: 72097b1fa2b063c628fe40c1f02557c40ee4eba0c25e020140511e6154b1e3bcf5b05d89d07c1cd10aaeec6b1b54f03fccd9b25415bf7bfa11661c2403d1a995
7
- data.tar.gz: c1d42e0efdcc0ba81dfd3fe7c885786c7e639d7a022c00d9999bfa48cd1c75d7d0cc7b8be13c143ce9e84ee017ce3571f24ecc024967c3fd9859af628d296abd
6
+ metadata.gz: 5315b48bff4207c58ff56242120cf6c9feb5297b29d668607241238ff9f1e0f01df16bf0ed45367b927690f6c55480b212761aec3dda0261a6af3ade1676e6b7
7
+ data.tar.gz: c00e64003cd9b3bb26685ed74dd16052e9b952cfa5e89baf0cf36f35d4d2cca77e3ee618c50d68f82d3e15aa2d239d45aebadea33b774ec507813ce15abfeb51
data/README.md CHANGED
@@ -24,7 +24,7 @@ gem install kabutops
24
24
  Or you can put it in your Gemfile
25
25
 
26
26
  ```ruby
27
- gem 'kabutops', '~> 0.0.12'
27
+ gem 'kabutops', '~> 0.0.13'
28
28
  ```
29
29
 
30
30
  You will also need Redis database installed and running.
@@ -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
@@ -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..1]
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
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Kabutops
4
- VERSION = '0.0.12'
4
+ VERSION = '0.0.13'
5
5
  end
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.12
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-16 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize