book-value 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a11cb94c2fb19399434dc294c4e173f13b606fda34cab984577f429a29e7806
4
- data.tar.gz: df5f6035353da19dd775e8b77f45eef7a4a81baa27bc0b3585fd2564254d04f3
3
+ metadata.gz: 8b2d13c166936168c1b4042f0b14aee46decf8a62306bdf8f89034ca2ec3cc44
4
+ data.tar.gz: 76b81b257574bc634ea5f4ab171eceec490c53131e115e115dd95cda9c7a23c9
5
5
  SHA512:
6
- metadata.gz: f57c9cdf267e562991df15e675bdff55475859e111f7cb0f4a65df3546fef5e0c2d3157c1dbf997ef2c9d25eddfb4f2ad1467004415c5e78bc8bc4bc942ae35e
7
- data.tar.gz: 8fbbe6a05a7d0099e708a1c43f4d21f97c146bcef883e636ed082873e01ca1609b5018c2d27c413d3d4fa75f711ab274d5ef1efd11954ae6d9b1331b3969bd5e
6
+ metadata.gz: 9ac3663a9f2c625a9b6ada1b4846b883165b533c0128e0988dda223263621333b6950d050681dea0e4712a741dcf7c550d4f7f77049cdd8273acea29c628bd17
7
+ data.tar.gz: e847aebdd63bfd45c68b1e9320391410741984e3f2c8f61d320143409719afde93b72bd0160dbf6826c417f2e6751fa8dd21f568a313325d853d59ec879a37bb
@@ -38,20 +38,22 @@ module BookValue
38
38
  options
39
39
  end
40
40
 
41
+ # TODO: Fix model to try `-`
41
42
  def car_features(make, model)
42
- raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
43
- doc = Nokogiri::HTML(raw_page['body'])
43
+ checkbox_options = {}
44
44
 
45
- raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
46
- doc = Nokogiri::HTML(raw_page['body'])
45
+ process_model(model) do |model_name|
46
+ raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model_name}")
47
+ next if raw_page == {}
47
48
 
48
- checkbox_options = {}
49
+ doc = Nokogiri::HTML(raw_page['body'])
49
50
 
50
- doc.css(".list-group li div").each do |checkbox|
51
- input_of_child = checkbox.children.find { |child| child.name == 'input' }
52
- label_of_child = checkbox.children.find { |child| child.name == 'label' }
51
+ doc.css(".list-group li div").each do |checkbox|
52
+ input_of_child = checkbox.children.find { |child| child.name == 'input' }
53
+ label_of_child = checkbox.children.find { |child| child.name == 'label' }
53
54
 
54
- checkbox_options[input_of_child[:name]] = label_of_child.children.first.to_s
55
+ checkbox_options[input_of_child[:name]] = label_of_child.children.first.to_s
56
+ end
55
57
  end
56
58
 
57
59
  checkbox_options
@@ -60,28 +62,40 @@ module BookValue
60
62
  # Features are just the list of features
61
63
  # condition_score is between 1-10, 10 is perfect, 1 is bad
62
64
  def get_book_value(make, model, features, mileage, year, condition_score = 10)
63
- feature_params = ""
65
+ output = ''
66
+ feature_params = ''
64
67
 
65
- features.each do |feature_id|
66
- feature_params = "#{feature_params}#{feature_id}=on&"
67
- end
68
+ process_model(model) do |model_name|
69
+ features.each do |feature_id|
70
+ feature_params = "#{feature_params}#{feature_id}=on&"
71
+ end
72
+
73
+ feature_params = feature_params[0..-2]
68
74
 
69
- feature_params = feature_params[0..-2]
75
+ milage_form_page = authorise_and_send(http_method: :post, payload: feature_params, command: "calculate/#{make.downcase}/#{model_name}")
76
+ next if milage_form_page == {}
70
77
 
71
- milage_form_page = authorise_and_send(http_method: :post, payload: feature_params, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
72
- condition_url = milage_form_page['headers']['location']
78
+ condition_url = milage_form_page['headers']['location']
73
79
 
74
- _condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
80
+ _condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
75
81
 
76
- book_value_url = condition_url.gsub('/4', '/5')
77
- book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
82
+ book_value_url = condition_url.gsub('/4', '/5')
83
+ book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
78
84
 
79
- doc = Nokogiri::HTML(book_value_page.body)
80
- doc.at('h4').text
85
+ doc = Nokogiri::HTML(book_value_page.body)
86
+
87
+ output = doc.at('h4').text
88
+ end
89
+
90
+ output
81
91
  end
82
92
 
83
93
  private
84
94
 
95
+ def process_model(model)
96
+ [model.downcase.gsub(' ', ''), model.downcase.gsub(' ', '-')]
97
+ end
98
+
85
99
  def img_path(name)
86
100
  "#{base_path}/data/makes/#{snake_case(name)}"
87
101
  end
@@ -1,3 +1,3 @@
1
1
  module BookValue
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: book-value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - trex22