hyper_miner 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hyper_miner.rb +1 -1
- data/lib/mine_plan.rb +55 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34a17673bbf0aeb1d6a30cbd070885d927a4eeae
|
4
|
+
data.tar.gz: 52f28d5c56367f326949821a48e3b00e810bf123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a10370b82eaafe0793fcadf9fd96dc33c82790ef76cfdba7336e593c78518fe1ff5e362b2deb04b07ee19d44e5de656112847d444923ba97d4baae4c178b6b2
|
7
|
+
data.tar.gz: 6d4fa5155fda0183fcf4628c49ebb101ada9f1825b676324e144b80461b65e0c4db50695399620e0ad3594648bb08b438d6c1bdcae4327248258e888a783ca4b
|
data/lib/hyper_miner.rb
CHANGED
data/lib/mine_plan.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class MinePlan
|
2
|
+
|
3
|
+
def initialize(html, &block)
|
4
|
+
@mined_data = {}
|
5
|
+
@html = html
|
6
|
+
|
7
|
+
@instructions = Proc.new { instance_eval(&block) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
@instructions.call
|
12
|
+
@mined_data
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def integer(name, options={})
|
18
|
+
value = get_value(options[:selector])
|
19
|
+
|
20
|
+
if value
|
21
|
+
@mined_data[name] = value.to_i
|
22
|
+
else
|
23
|
+
@mined_data[name] = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def text(name, options={})
|
28
|
+
value = get_value(options[:selector])
|
29
|
+
|
30
|
+
if value
|
31
|
+
@mined_data[name] = value
|
32
|
+
else
|
33
|
+
@mined_data[name] = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def query(selector)
|
38
|
+
matching = Nokogiri::HTML(@html).css(selector)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_collection(selector)
|
42
|
+
query(selector).map(&:text)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_value(selector)
|
46
|
+
matches = query(selector)
|
47
|
+
|
48
|
+
if matches.any?
|
49
|
+
matches[0].text
|
50
|
+
else
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyper_miner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deyan Dobrinov
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/hyper_miner.rb
|
20
|
+
- lib/mine_plan.rb
|
20
21
|
homepage: https://github.com/dobrinov/hyper_miner
|
21
22
|
licenses:
|
22
23
|
- MIT
|