Method: TecDoc::Article#linked_vehicles_with_details
- Defined in:
- lib/tec_doc/article.rb
#linked_vehicles_with_details(options = {}) ⇒ Object
Linked vehicles for article with car specific attributes
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/tec_doc/article.rb', line 249 def linked_vehicles_with_details( = {}) unless @linked_vehicles_with_details links = linked_targets.map do |link| new_link = link.dup new_link.delete(:linking_target_type) new_link end batch_list = links.each_slice(25).to_a # Response from all batches response = batch_list.inject([]) do |result, long_list| result += TecDoc.client.request(:get_article_linked_all_linking_targets_by_ids_2, { :linked_article_pairs => { :array => {:pairs => long_list} }, :lang => scope[:lang], :country => scope[:country], :linking_target_type => "C", :immediate_attributs => true, :article_id => id }) result end @linked_vehicles_with_details = response.map do |attrs| details = (attrs[:linked_vehicles].to_a[0] || {}) vehicle = Vehicle.new vehicle.id = details[:car_id].to_i vehicle.name = "#{details[:manu_desc]} - #{details[:model_desc]} - #{details[:car_desc]}" vehicle.manu_id = details[:manu_id].to_i vehicle.mod_id = details[:model_id].to_i vehicle.power_hp_from = details[:power_hp_from].to_i vehicle.power_kw_from = details[:power_kw_from].to_i vehicle.power_hp_to = details[:power_hp_to].to_i vehicle.power_kw_to = details[:power_kw_to].to_i vehicle.cylinder_capacity = details[:cylinder_capacity].to_i vehicle.date_of_construction_from = DateParser.new(details[:year_of_construction_from]).to_date vehicle.date_of_construction_to = DateParser.new(details[:year_of_construction_to]).to_date vehicle.attributes = attrs[:linked_article_immediate_attributs].to_a vehicle.article_link_id = attrs[:article_link_id].to_i vehicle end end @linked_vehicles_with_details end |