aws-rds-instance_types 0.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +30 -44
- data/aws-rds-instance_types.gemspec +2 -3
- data/bin/aws-rds-instance_types +5 -2
- data/lib/dldinternet/aws/rds/instance_types.rb +4 -0
- data/lib/dldinternet/aws/rds/instance_types/cli.rb +8 -12
- data/lib/dldinternet/aws/rds/instance_types/mixins/rds_instance_types.rb +15 -18
- data/lib/dldinternet/aws/rds/instance_types/version.rb +1 -1
- metadata +18 -33
- data/lib/dldinternet/aws/rds/instance_types/scraper.rb +0 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcba97319bcf1b19cf050082339a48a67db82430
|
4
|
+
data.tar.gz: fdc641c8c55dc49d294079529e6ccbb95c3068ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a660e45d24bdf893b61b769a02eb8b627eaaf7efa1d6f7259741a4a6968fa80bf84dcfb251a624cf2756e22cf395cec84c8b395ee13e28214208a7c17395fee1
|
7
|
+
data.tar.gz: da17e8027c5f54ecaa5fe3da2efb62d86d4511ab389929931ff7ea0ae9e3f6d3d1400cb7de1af9e9b7e172d5a847ad29d542f1714c5f81722811c19d9f7777d6
|
data/Gemfile.lock
CHANGED
@@ -1,72 +1,55 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aws-rds-instance_types (0.
|
4
|
+
aws-rds-instance_types (2.0.0)
|
5
5
|
awesome_print (> 0)
|
6
|
+
aws-ec2-instance_types (>= 2.0.0)
|
6
7
|
colorize
|
7
|
-
dldinternet-mixlib-logging (>= 0.
|
8
|
+
dldinternet-mixlib-logging (>= 0.7.1)
|
8
9
|
inifile (> 0)
|
9
10
|
json
|
10
|
-
mechanize (>= 2.7.2)
|
11
|
-
nokogiri (>= 1.5.0)
|
12
11
|
psych
|
13
12
|
thor (>= 0.19.1)
|
14
13
|
|
15
14
|
GEM
|
16
15
|
remote: https://rubygems.org/
|
17
16
|
specs:
|
18
|
-
awesome_print (1.
|
19
|
-
|
20
|
-
|
17
|
+
awesome_print (1.8.0)
|
18
|
+
aws-ec2-instance_types (2.0.0)
|
19
|
+
awesome_print (> 0)
|
20
|
+
colorize
|
21
|
+
dldinternet-mixlib-logging (>= 0.7.1)
|
22
|
+
inifile (> 0)
|
23
|
+
json
|
24
|
+
psych
|
25
|
+
thor (>= 0.19.1)
|
26
|
+
builder (3.2.3)
|
27
|
+
colorize (0.8.1)
|
21
28
|
cucumber (0.10.7)
|
22
29
|
builder (>= 2.1.2)
|
23
30
|
diff-lcs (>= 1.1.2)
|
24
31
|
gherkin (~> 2.4.0)
|
25
32
|
json (>= 1.4.6)
|
26
33
|
term-ansicolor (>= 1.0.5)
|
27
|
-
diff-lcs (1.
|
28
|
-
dldinternet-mixlib-logging (0.
|
29
|
-
logging (~> 1
|
30
|
-
domain_name (0.5.22)
|
31
|
-
unf (>= 0.0.5, < 1.0.0)
|
34
|
+
diff-lcs (1.3)
|
35
|
+
dldinternet-mixlib-logging (0.7.1)
|
36
|
+
logging (~> 2.1, >= 2.1.0)
|
32
37
|
gherkin (2.4.21)
|
33
38
|
json (>= 1.4.6)
|
34
|
-
http-cookie (1.0.2)
|
35
|
-
domain_name (~> 0.5)
|
36
39
|
inifile (3.0.0)
|
37
|
-
json (1.
|
38
|
-
little-plugger (1.1.
|
39
|
-
logging (
|
40
|
-
little-plugger (
|
41
|
-
multi_json (
|
42
|
-
|
43
|
-
|
44
|
-
http-cookie (~> 1.0)
|
45
|
-
mime-types (~> 2.0)
|
46
|
-
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
47
|
-
net-http-persistent (~> 2.5, >= 2.5.2)
|
48
|
-
nokogiri (~> 1.4)
|
49
|
-
ntlm-http (~> 0.1, >= 0.1.1)
|
50
|
-
webrobots (>= 0.0.9, < 0.2)
|
51
|
-
mime-types (2.4.3)
|
52
|
-
mini_portile (0.6.1)
|
53
|
-
multi_json (1.10.1)
|
54
|
-
net-http-digest_auth (1.4)
|
55
|
-
net-http-persistent (2.9.4)
|
56
|
-
nokogiri (1.6.4.1)
|
57
|
-
mini_portile (~> 0.6.0)
|
58
|
-
ntlm-http (0.1.1)
|
59
|
-
psych (2.0.6)
|
40
|
+
json (2.1.0)
|
41
|
+
little-plugger (1.1.4)
|
42
|
+
logging (2.2.2)
|
43
|
+
little-plugger (~> 1.1)
|
44
|
+
multi_json (~> 1.10)
|
45
|
+
multi_json (1.13.1)
|
46
|
+
psych (3.0.2)
|
60
47
|
rake (0.9.6)
|
61
48
|
rubygems-tasks (0.2.4)
|
62
|
-
term-ansicolor (1.
|
49
|
+
term-ansicolor (1.6.0)
|
63
50
|
tins (~> 1.0)
|
64
|
-
thor (0.
|
65
|
-
tins (1.
|
66
|
-
unf (0.1.4)
|
67
|
-
unf_ext
|
68
|
-
unf_ext (0.0.6)
|
69
|
-
webrobots (0.1.1)
|
51
|
+
thor (0.20.0)
|
52
|
+
tins (1.16.3)
|
70
53
|
|
71
54
|
PLATFORMS
|
72
55
|
ruby
|
@@ -77,3 +60,6 @@ DEPENDENCIES
|
|
77
60
|
cucumber (~> 0.10.2)
|
78
61
|
rake (~> 0.8)
|
79
62
|
rubygems-tasks (~> 0.2)
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
1.16.1
|
@@ -22,12 +22,11 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
23
23
|
|
24
24
|
gem.add_runtime_dependency('thor', ['>= 0.19.1'])
|
25
|
-
gem.add_runtime_dependency(%q<mechanize>, ['>= 2.7.2'])
|
26
|
-
gem.add_runtime_dependency(%q<nokogiri>, ['>= 1.5.0'])
|
27
25
|
gem.add_dependency 'awesome_print', '> 0'
|
28
26
|
gem.add_dependency 'inifile', '> 0'
|
29
27
|
gem.add_dependency 'colorize', '>= 0'
|
30
|
-
gem.add_dependency 'dldinternet-mixlib-logging', '>= 0.
|
28
|
+
gem.add_dependency 'dldinternet-mixlib-logging', '>= 0.7.1'
|
29
|
+
gem.add_dependency 'aws-ec2-instance_types', '>= 2.0.0'
|
31
30
|
gem.add_dependency 'psych'
|
32
31
|
gem.add_dependency 'json'
|
33
32
|
end
|
data/bin/aws-rds-instance_types
CHANGED
@@ -7,10 +7,13 @@ require 'dldinternet/aws/rds/instance_types/cli'
|
|
7
7
|
|
8
8
|
# =====================================================================================================================
|
9
9
|
rc = DLDInternet::AWS::RDS::Instance_Types::Cli.start(ARGV)
|
10
|
-
if rc.is_a?(
|
10
|
+
if rc.is_a?(Integer)
|
11
11
|
exit rc
|
12
|
+
elsif rc.is_a?(IO)
|
13
|
+
exit 0
|
12
14
|
else
|
13
|
-
|
15
|
+
$stderr.write "\n#{File.basename(__FILE__)}: \$? was '" + rc.ai + "'\n\n"
|
14
16
|
exit 0
|
15
17
|
end
|
16
18
|
|
19
|
+
|
@@ -1,23 +1,20 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'awesome_print'
|
3
3
|
require 'colorize'
|
4
|
-
require 'dldinternet/aws/rds/instance_types/version'
|
5
|
-
require 'dldinternet/aws/rds/instance_types/error'
|
6
|
-
require 'dldinternet/aws/rds/instance_types/scraper'
|
7
|
-
require 'dldinternet/aws/rds/instance_types/cli'
|
8
4
|
require 'dldinternet/aws/rds/instance_types'
|
9
5
|
|
10
6
|
module DLDInternet
|
11
7
|
module AWS
|
12
8
|
module RDS
|
13
9
|
module Instance_Types
|
10
|
+
# noinspection RubyParenthesesAfterMethodCallInspection
|
14
11
|
class Cli < Thor
|
15
12
|
class_option :verbose, :type => :boolean
|
16
13
|
class_option :debug, :type => :boolean
|
17
14
|
class_option :log_level, :type => :string, :banner => 'Log level ([:trace, :debug, :info, :step, :warn, :error, :fatal, :todo])'
|
18
15
|
class_option :inifile, :type => :string
|
19
16
|
class_option :help, :type => :boolean
|
20
|
-
class_option :format, :type => :string, :default => 'pretty', :banner => '[:pretty, :yaml, :json]'
|
17
|
+
class_option :format, :type => :string, :default => 'pretty', :banner => '[:pretty, :yaml, :json]', :aliases => ['--output']
|
21
18
|
|
22
19
|
no_commands do
|
23
20
|
|
@@ -48,7 +45,7 @@ module DLDInternet
|
|
48
45
|
parse_options
|
49
46
|
puts 'get instance types' if options[:verbose]
|
50
47
|
|
51
|
-
it = DLDInternet::AWS::RDS::Instance_Types.
|
48
|
+
it = DLDInternet::AWS::RDS::Instance_Types.get_rds_instance_types()
|
52
49
|
case options[:format]
|
53
50
|
when /yaml/
|
54
51
|
puts it.to_yaml line_width: 1024, indentation: 4, canonical: false
|
@@ -60,22 +57,22 @@ module DLDInternet
|
|
60
57
|
0
|
61
58
|
end
|
62
59
|
|
63
|
-
desc 'load
|
60
|
+
desc 'load PATH', 'load instance types'
|
64
61
|
def load(path)
|
65
62
|
parse_options
|
66
63
|
puts 'load instance types' if options[:verbose]
|
67
64
|
|
68
|
-
it = DLDInternet::AWS::RDS::Instance_Types.
|
65
|
+
it = DLDInternet::AWS::RDS::Instance_Types.load_rds_instance_types(path)
|
69
66
|
ap it
|
70
67
|
end
|
71
68
|
|
72
|
-
desc 'save', 'save instance types'
|
69
|
+
desc 'save PATH', 'save instance types'
|
73
70
|
def save(path)
|
74
71
|
parse_options
|
75
72
|
puts 'save instance types' if options[:verbose]
|
76
73
|
|
77
|
-
it = DLDInternet::AWS::
|
78
|
-
DLDInternet::AWS::
|
74
|
+
it = DLDInternet::AWS::RDS::Instance_Types.get_rds_instance_types()
|
75
|
+
DLDInternet::AWS::RDS::Instance_Types.save_rds_instance_types(path, it)
|
79
76
|
end
|
80
77
|
|
81
78
|
default_task 'get'
|
@@ -84,4 +81,3 @@ module DLDInternet
|
|
84
81
|
end
|
85
82
|
end
|
86
83
|
end
|
87
|
-
|
@@ -2,7 +2,8 @@ require 'thor'
|
|
2
2
|
require 'awesome_print'
|
3
3
|
require 'inifile'
|
4
4
|
require 'colorize'
|
5
|
-
require 'dldinternet/aws/
|
5
|
+
require 'dldinternet/aws/ec2/instance_types/aws-pricing-api-client'
|
6
|
+
require 'yaml'
|
6
7
|
|
7
8
|
module DLDInternet
|
8
9
|
module AWS
|
@@ -11,7 +12,7 @@ module DLDInternet
|
|
11
12
|
module MixIns
|
12
13
|
module RDS_Instance_Types
|
13
14
|
|
14
|
-
def
|
15
|
+
def get_file_format(path)
|
15
16
|
format = case File.extname(File.basename(path)).downcase
|
16
17
|
when /json|js/
|
17
18
|
'json'
|
@@ -22,8 +23,8 @@ module DLDInternet
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
def
|
26
|
-
format =
|
26
|
+
def save_rds_instance_types(path, it)
|
27
|
+
format = get_file_format(path)
|
27
28
|
begin
|
28
29
|
File.open path, File::CREAT|File::TRUNC|File::RDWR, 0644 do |f|
|
29
30
|
case format
|
@@ -43,13 +44,14 @@ module DLDInternet
|
|
43
44
|
0
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
format =
|
47
|
+
def load_rds_instance_types(path)
|
48
|
+
format = get_file_format(path)
|
48
49
|
spec = File.read(path)
|
49
50
|
case format
|
50
51
|
when /json/
|
51
52
|
JSON.parse(spec)
|
52
|
-
|
53
|
+
when /yaml/
|
54
|
+
YAML.load File.read(path)
|
53
55
|
else
|
54
56
|
begin
|
55
57
|
YAML.load(spec)
|
@@ -61,20 +63,15 @@ module DLDInternet
|
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
require 'mechanize'
|
67
|
-
mechanize = ::Mechanize.new
|
68
|
-
mechanize.open_timeout = 5
|
69
|
-
mechanize.read_timeout = 10
|
70
|
-
end
|
66
|
+
# noinspection RubyParenthesesAfterMethodCallInspection
|
67
|
+
def get_rds_instance_types()
|
71
68
|
|
72
|
-
|
69
|
+
client = DLDInternet::AWS::EC2::Instance_Types::AWSPricingAPIClient.new()
|
73
70
|
|
74
71
|
begin
|
75
|
-
return
|
76
|
-
rescue
|
77
|
-
puts "Unable to retrieve instance type details
|
72
|
+
return client.get_instance_types(url: 'https://ec2instances.info/rds/instances.json')
|
73
|
+
rescue Exception => e
|
74
|
+
puts "Unable to retrieve instance type details. Giving up ...".light_red
|
78
75
|
return nil
|
79
76
|
end
|
80
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-rds-instance_types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christo De Lange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,35 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.19.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 2.7.2
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 2.7.2
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: nokogiri
|
70
|
+
name: awesome_print
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - ">"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
75
|
+
version: '0'
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - ">"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: inifile
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">"
|
@@ -109,47 +95,47 @@ dependencies:
|
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: colorize
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - "
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- - "
|
108
|
+
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
112
|
+
name: dldinternet-mixlib-logging
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - ">="
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
117
|
+
version: 0.7.1
|
132
118
|
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - ">="
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
124
|
+
version: 0.7.1
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
126
|
+
name: aws-ec2-instance_types
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - ">="
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
131
|
+
version: 2.0.0
|
146
132
|
type: :runtime
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - ">="
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
138
|
+
version: 2.0.0
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: psych
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,7 +194,6 @@ files:
|
|
208
194
|
- lib/dldinternet/aws/rds/instance_types/error.rb
|
209
195
|
- lib/dldinternet/aws/rds/instance_types/mixins/no_commands.rb
|
210
196
|
- lib/dldinternet/aws/rds/instance_types/mixins/rds_instance_types.rb
|
211
|
-
- lib/dldinternet/aws/rds/instance_types/scraper.rb
|
212
197
|
- lib/dldinternet/aws/rds/instance_types/version.rb
|
213
198
|
homepage: https://rubygems.org/gems/aws-rds-instance_types
|
214
199
|
licenses:
|
@@ -230,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
215
|
version: '0'
|
231
216
|
requirements: []
|
232
217
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
218
|
+
rubygems_version: 2.6.13
|
234
219
|
signing_key:
|
235
220
|
specification_version: 4
|
236
221
|
summary: Retrieve an up to date list of valid AWS RDS Instance Types directly from
|
@@ -1,128 +0,0 @@
|
|
1
|
-
module DLDInternet
|
2
|
-
module AWS
|
3
|
-
module RDS
|
4
|
-
module Instance_Types
|
5
|
-
HEADINGS = [
|
6
|
-
:Instance_Type,
|
7
|
-
:vCPU,
|
8
|
-
:Memory,
|
9
|
-
:PIOPS_Optimized,
|
10
|
-
:Network_Performance,
|
11
|
-
:Generation,
|
12
|
-
]
|
13
|
-
DEBUG = true
|
14
|
-
class Scraper
|
15
|
-
attr_reader :instance_types
|
16
|
-
|
17
|
-
# ---------------------------------------------------------------------------------------------------------------
|
18
|
-
def initialize
|
19
|
-
@instance_types = {}
|
20
|
-
end
|
21
|
-
|
22
|
-
# ---------------------------------------------------------------------------------------------------------------
|
23
|
-
def getInstanceTypes(options={})
|
24
|
-
unless @instance_types.size > 0
|
25
|
-
require 'mechanize'
|
26
|
-
mechanize = options[:mechanize]
|
27
|
-
unless mechanize
|
28
|
-
mechanize = Mechanize.new
|
29
|
-
mechanize.user_agent_alias = 'Mac Safari' # Pretend to use a Mac
|
30
|
-
end
|
31
|
-
url = options[:url] || 'http://aws.amazon.com/rds/details/'
|
32
|
-
|
33
|
-
page = mechanize.get(url)
|
34
|
-
|
35
|
-
require 'nokogiri'
|
36
|
-
|
37
|
-
nk = Nokogiri::HTML(page.body)
|
38
|
-
div = nk.css('div#aws-page-content')
|
39
|
-
div = nk.css('div.page-content') unless div.to_s.match %r'^<div id="'m
|
40
|
-
# noinspection RubyAssignmentExpressionInConditionalInspection
|
41
|
-
if div = find_div(div, %r'^<div\s+class="nine columns content-with-nav')
|
42
|
-
# noinspection RubyAssignmentExpressionInConditionalInspection
|
43
|
-
if div = find_div(div, %r'^<div\s+class="content parsys')
|
44
|
-
divs = div.css('div').to_a
|
45
|
-
itm = nil
|
46
|
-
idx = 0
|
47
|
-
divs.each do |d|
|
48
|
-
as = d.css('div div h2 a')
|
49
|
-
as.each do |a|
|
50
|
-
# puts "'#{a.text}'"
|
51
|
-
if a.text.match %r'\s*DB Instance Classes\s*'
|
52
|
-
itm = d
|
53
|
-
break
|
54
|
-
end
|
55
|
-
end
|
56
|
-
break if itm
|
57
|
-
idx += 1
|
58
|
-
end
|
59
|
-
if idx < divs.count
|
60
|
-
divs = divs[idx..-1]
|
61
|
-
table = nil
|
62
|
-
divs.each do |d|
|
63
|
-
table = d.css('div.aws-table table')
|
64
|
-
break if table.to_s.match(%r'^<table'i)
|
65
|
-
end
|
66
|
-
|
67
|
-
@instance_types = scrapeTable(HEADINGS, table) if table
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
@instance_types
|
73
|
-
end
|
74
|
-
|
75
|
-
def find_div(nk,regex)
|
76
|
-
ret = nil
|
77
|
-
divs = nk.search('div')
|
78
|
-
if divs.count > 0
|
79
|
-
nine = divs.select { |div| div.to_s.match regex }
|
80
|
-
if nine.count >= 1
|
81
|
-
nine = nine.shift
|
82
|
-
ret = nine
|
83
|
-
end
|
84
|
-
end
|
85
|
-
ret
|
86
|
-
end
|
87
|
-
|
88
|
-
# ---------------------------------------------------------------------------------------------------------------
|
89
|
-
def scrapeTable(cHeadings,table)
|
90
|
-
raise Error.new 'Cannot find instance type table' unless (table.is_a?(Nokogiri::XML::Element) or table.is_a?(Nokogiri::XML::NodeSet))
|
91
|
-
rows = table.search('tr')[0..-1]
|
92
|
-
head = rows.shift
|
93
|
-
|
94
|
-
cols = head.search('td').collect { |td|
|
95
|
-
text = td.text.to_s
|
96
|
-
text = text.gsub(%r/(\r?\n)+/, ' ').strip
|
97
|
-
CGI.unescapeHTML(text)
|
98
|
-
}
|
99
|
-
instance_types = {
|
100
|
-
:headings => {},
|
101
|
-
:details => []
|
102
|
-
}
|
103
|
-
(0..cols.size-1).map { |i| instance_types[:headings][cHeadings[i]] = cols[i] }
|
104
|
-
instance_types[:headings][cHeadings[-1]] = 'Generation'
|
105
|
-
instance_set = nil
|
106
|
-
rows.each do |row|
|
107
|
-
|
108
|
-
cells = row.search('td').collect { |td|
|
109
|
-
CGI.unescapeHTML(td.text.to_s.gsub(%r/(\r?\n)+/, ' ').strip)
|
110
|
-
}
|
111
|
-
if cells.count == 1 or (cells[1] == cells[2] and cells[2] == cells[4])
|
112
|
-
instance_set = cells[0]
|
113
|
-
else
|
114
|
-
raise StandardError.new "This row does not have the same number of cells as the table header: #{row.text.to_s.strip}" unless cells.size == cols.size
|
115
|
-
instance = {}
|
116
|
-
(0..cells.size-1).map { |i| instance[cHeadings[i]] = cells[i] }
|
117
|
-
instance[cHeadings[-1]] = instance_set
|
118
|
-
instance_types[:details] << instance
|
119
|
-
end
|
120
|
-
end
|
121
|
-
instance_types
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|