chrome_data 0.0.2 → 0.0.3

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: 8afb6ab74cdffac02f50225de7260a9ef4e1456a
4
- data.tar.gz: 33e84a8718d9cfe54b5e255ddf68a474a93138cd
3
+ metadata.gz: 4f19cb8fe3b11f82c90ffa574d510307e8e03181
4
+ data.tar.gz: feac33288c42d9491f7c1fac507d7eda3c77baa3
5
5
  SHA512:
6
- metadata.gz: e6cdddc5b6a76f2d4d5e103f17961daa30945f5fb8e8abb9be8c10f5316415061dc4fd8bab1a7026dddfb8da1338d834e822136a0b4512a51a9d7c43fe910d90
7
- data.tar.gz: c9cec11f40b545fdcb87ab665b0b9b73d1584ba2c4a06a9cb972bfa0a82260ef22be0be34d8a01cab9ce323dee0a0646567d98b3338055315360a22554d3fcae
6
+ metadata.gz: 0426f9a5c64f87b3e4d494704048dd8cd463138b5714e1da84b84aa831f44c9bb408832561a4bddb024de1c1c6a691f4fdfdc561769bcd2d74b0dc1ffbf677e6
7
+ data.tar.gz: c9f2cbc36d80a00c91c7f0efd122dff82485f1a3327cbc473e36db9da3e61fb86c27b880020c20caf56871748a1e42180e4890d1a0c98acbdbbb47c2caae640e
data/chrome_data.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'chrome_data/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "chrome_data"
8
8
  spec.version = ChromeData::VERSION
9
- spec.authors = ["Jim Ryan"]
10
- spec.email = ["jim@room118solutions.com"]
9
+ spec.authors = ["Jim Ryan", "JC Grubbs", "Tony Coconate", "Cory Stephenson", "Zach Briggs"]
10
+ spec.email = ["jim@room118solutions.com", "jc@devmynd.com", "me@tonycoconate.com", "aevin@me.com", "briggszj@gmail.com"]
11
11
  spec.description = %q{Provides a ruby interface for Chrome Data's API. Read more about it here: http://www.chromedata.com/}
12
12
  spec.summary = %q{A ruby interface for Chrome Data's API}
13
13
  spec.homepage = "http://github.com/room118solutions/chrome_data"
@@ -12,4 +12,4 @@ module ChromeData
12
12
  end
13
13
 
14
14
  end
15
- end
15
+ end
@@ -2,42 +2,97 @@ module ChromeData
2
2
  class Vehicle < BaseRequest
3
3
  class Engine < Struct.new(:type); end
4
4
 
5
- attr_accessor :model_year, :division, :model, :styles, :engines
5
+ attr_accessor :model_year, :division, :model, :styles, :engines, :standard
6
6
 
7
- class << self
8
- def request_name
9
- "describeVehicle"
7
+ def self.request_name
8
+ "describeVehicle"
9
+ end
10
+
11
+ def self.find_by_vin(vin)
12
+ request 'vin' => vin
13
+ end
14
+
15
+ def self.parse_response(response)
16
+ return unless find_elements('vinDescription', response).first
17
+ self.new response
18
+ end
19
+
20
+ private
21
+ def initialize(response)
22
+ vin_description = self.class.find_elements('vinDescription', response).first
23
+ @model_year = vin_description.attr('modelYear').to_i
24
+ @division = vin_description.attr('division')
25
+ @model = vin_description.attr('modelName')
26
+ parse_styles response
27
+ parse_standard response
28
+ parse_engines response
29
+ end
30
+
31
+ def parse_styles(response)
32
+ @styles = self.class.find_elements('style', response).map do |e|
33
+ create_style e, response
34
+ end
35
+ end
36
+
37
+ def parse_standard(response)
38
+ @standard = self.class.find_elements('standard', response).map { |e|
39
+ {
40
+ "id" => find_standard_id(e),
41
+ "description" => find_standard_description(e),
42
+ "category" => find_standard_category(e),
43
+ "style_ids" => collect_style_ids(e, response)
44
+ }
45
+ }
46
+ end
47
+
48
+ def parse_engines(response)
49
+ @engines = self.class.find_elements('engine', response).map do |e|
50
+ Engine.new(e.at_xpath("x:engineType", 'x' => response.body.namespace.href).text)
10
51
  end
52
+ end
53
+
54
+ def create_style(element, response)
55
+ Style.new(
56
+ id: element.attr('id').to_i,
57
+ name: element.attr('name'),
58
+ trim: element.attr('trim'),
59
+ name_without_trim: element.attr('nameWoTrim'),
60
+ body_types: collect_body_types(element, response)
61
+ )
62
+ end
11
63
 
12
- def find_by_vin(vin)
13
- request 'vin' => vin
64
+ def collect_body_types(element, response)
65
+ element.xpath("x:bodyType", 'x' => response.body.namespace.href).map { |bt|
66
+ Style::BodyType.new(bt.attr('id').to_i, bt.text)
67
+ }
68
+ end
69
+
70
+ def find_standard_id(element)
71
+ if id = find(element, "header")
72
+ id.attributes["id"].value.to_i
14
73
  end
74
+ end
15
75
 
16
- def parse_response(response)
17
- if vin_description = find_elements('vinDescription', response).first
18
- new.tap do |v|
19
- v.model_year = vin_description.attr('modelYear').to_i
20
- v.division = vin_description.attr('division')
21
- v.model = vin_description.attr('modelName')
22
-
23
- v.styles = find_elements('style', response).map do |e|
24
- Style.new(
25
- id: e.attr('id').to_i,
26
- name: e.attr('name'),
27
- trim: e.attr('trim'),
28
- name_without_trim: e.attr('nameWoTrim'),
29
- body_types: e.xpath("x:bodyType", 'x' => response.body.namespace.href).map do |bt|
30
- Style::BodyType.new(bt.attr('id').to_i, bt.text)
31
- end
32
- )
33
- end
34
-
35
- v.engines = find_elements('engine', response).map do |e|
36
- Engine.new(e.at_xpath("x:engineType", 'x' => response.body.namespace.href).text)
37
- end
38
- end
39
- end
76
+ def find_standard_description(element)
77
+ if desc = find(element, "description")
78
+ desc.text
40
79
  end
41
80
  end
81
+
82
+ def find_standard_category(element)
83
+ if cat = find(element, "header")
84
+ cat.text
85
+ end
86
+ end
87
+
88
+ def find(element, target)
89
+ element.children.find { |e| e.name == target }
90
+ end
91
+
92
+ def collect_style_ids(element, response)
93
+ element.xpath("x:styleId", 'x' => response.body.namespace.href).map { |style_id|
94
+ style_id.text.to_i
95
+ }
96
+ end
42
97
  end
43
- end
98
+ end
@@ -1,3 +1,3 @@
1
1
  module ChromeData
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -35,6 +35,29 @@ describe ChromeData::Vehicle do
35
35
  @vehicle.model.must_equal 'C-Class'
36
36
  end
37
37
 
38
+ describe 'standard' do
39
+ before do
40
+ @standard = @vehicle.standard[0]
41
+ end
42
+
43
+ it "sets id" do
44
+ @standard.fetch("id").must_equal 1236
45
+ end
46
+
47
+ it "sets description" do
48
+ @standard.fetch("description").
49
+ must_equal "1.8L 16-valve I4 turbocharged engine"
50
+ end
51
+
52
+ it "sets category" do
53
+ @standard.fetch("category").must_equal "MECHANICAL"
54
+ end
55
+
56
+ it "sets style_ids" do
57
+ @standard.fetch("style_ids").must_equal [337364, 337365]
58
+ end
59
+ end
60
+
38
61
  describe 'styles' do
39
62
  it 'sets id' do
40
63
  @vehicle.styles[0].id.must_equal 337364
metadata CHANGED
@@ -1,14 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrome_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Ryan
8
+ - JC Grubbs
9
+ - Tony Coconate
10
+ - Cory Stephenson
11
+ - Zach Briggs
8
12
  autorequire:
9
13
  bindir: bin
10
14
  cert_chain: []
11
- date: 2013-06-05 00:00:00.000000000 Z
15
+ date: 2013-06-14 00:00:00.000000000 Z
12
16
  dependencies:
13
17
  - !ruby/object:Gem::Dependency
14
18
  name: bundler
@@ -140,6 +144,10 @@ description: 'Provides a ruby interface for Chrome Data''s API. Read more about
140
144
  here: http://www.chromedata.com/'
141
145
  email:
142
146
  - jim@room118solutions.com
147
+ - jc@devmynd.com
148
+ - me@tonycoconate.com
149
+ - aevin@me.com
150
+ - briggszj@gmail.com
143
151
  executables: []
144
152
  extensions: []
145
153
  extra_rdoc_files: []