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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hyper_miner.rb +1 -1
  3. data/lib/mine_plan.rb +55 -0
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf1e8cfa9901db5f82d7df9c39fd0f2ec16d7318
4
- data.tar.gz: 7806a01001dd4bfda35232d4d27e6a234205ce2a
3
+ metadata.gz: 34a17673bbf0aeb1d6a30cbd070885d927a4eeae
4
+ data.tar.gz: 52f28d5c56367f326949821a48e3b00e810bf123
5
5
  SHA512:
6
- metadata.gz: ce5d55d6bd9d95f97326964189886843402a32c1961b6bbfbb8bf0a331bf7c67016b72e0428191482a2f0a0d54908e5f345975fe12618b257873f4cb074c8271
7
- data.tar.gz: cba352a5599c7be87c17b685ff9af4c83f4a2a3f3eb56bf12646f771a24559ff1c39fd25fd18d58602aeabac590a8a8be9612de70afcca905e4f292fc5cf223f
6
+ metadata.gz: 7a10370b82eaafe0793fcadf9fd96dc33c82790ef76cfdba7336e593c78518fe1ff5e362b2deb04b07ee19d44e5de656112847d444923ba97d4baae4c178b6b2
7
+ data.tar.gz: 6d4fa5155fda0183fcf4628c49ebb101ada9f1825b676324e144b80461b65e0c4db50695399620e0ad3594648bb08b438d6c1bdcae4327248258e888a783ca4b
@@ -1,7 +1,7 @@
1
1
  require 'open-uri'
2
2
  require 'nokogiri'
3
3
 
4
- require_relative './mine_plan.rb'
4
+ require "mine_plan.rb"
5
5
 
6
6
  class HyperMiner
7
7
 
@@ -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.1
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