Class: TecDoc::Article
- Inherits:
-
Object
- Object
- TecDoc::Article
- Defined in:
- lib/tec_doc/article.rb
Instance Attribute Summary collapse
-
#brand_name ⇒ Object
Returns the value of attribute brand_name.
-
#brand_number ⇒ Object
Returns the value of attribute brand_number.
-
#generic_article_id ⇒ Object
Returns the value of attribute generic_article_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#number_type ⇒ Object
Returns the value of attribute number_type.
-
#packing_unit ⇒ Object
Returns the value of attribute packing_unit.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#search_number ⇒ Object
Returns the value of attribute search_number.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
-
.all(options) ⇒ Array<TecDoc::Article>
All articles by linked vehicle and brand number, generic article and assembly group.
-
.all_with_details(options) ⇒ Array<TecDoc::Article>
All requested articles detail information.
-
.search(options = {}) ⇒ Array<TecDoc::Article>
Find article by all number types and brand number and generic article id.
Instance Method Summary collapse
- #attributes ⇒ Object
- #brand ⇒ Object
- #documents ⇒ Object
- #ean_number ⇒ Object
- #information ⇒ Object
-
#initialize(attributes = {}, scope = {}) ⇒ Article
constructor
A new instance of Article.
- #linked_manufacturers ⇒ Object
-
#linked_targets ⇒ Object
Array with all linked target vehicles with article link id If request entity is too large, we have to request linked targets by manufacturers.
- #linked_vehicle_ids ⇒ Object
- #linked_vehicles(options = {}) ⇒ Object
-
#linked_vehicles_with_details(options = {}) ⇒ Object
Linked vehicles for article with car specific attributes.
- #oe_numbers ⇒ Object
- #thumbnails ⇒ Object
- #trade_numbers ⇒ Object
Constructor Details
#initialize(attributes = {}, scope = {}) ⇒ Article
Returns a new instance of Article.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/tec_doc/article.rb', line 81 def initialize(attributes = {}, scope = {}) article_data = (attributes[:direct_article] || attributes) @id = article_data[:article_id].to_i @name = article_data[:article_name].to_s @number = article_data[:article_no].to_s @brand_name = article_data[:brand_name].to_s @brand_number = article_data[:brand_no].to_i @generic_article_id = article_data[:generic_article_id].to_i @number_type = article_data[:number_type].to_i @search_number = article_data[:article_search_no].to_s @state = article_data[:article_state_name] @scope = scope @ean_number = attributes[:ean_number].to_a.map(&:values).flatten.first @trade_number = attributes[:usage_numbers].to_a.map(&:values).flatten.first if attributes[:article_attributes] @attributes = attributes[:article_attributes].map do |attrs| ArticleAttribute.new(attrs) end end if attributes[:oen_numbers] @oe_numbers = attributes[:oen_numbers].map do |attrs| ArticleOENumber.new(attrs) end end end |
Instance Attribute Details
#brand_name ⇒ Object
Returns the value of attribute brand_name.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def brand_name @brand_name end |
#brand_number ⇒ Object
Returns the value of attribute brand_number.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def brand_number @brand_number end |
#generic_article_id ⇒ Object
Returns the value of attribute generic_article_id.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def generic_article_id @generic_article_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def number @number end |
#number_type ⇒ Object
Returns the value of attribute number_type.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def number_type @number_type end |
#packing_unit ⇒ Object
Returns the value of attribute packing_unit.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def packing_unit @packing_unit end |
#scope ⇒ Object
Returns the value of attribute scope.
6 7 8 |
# File 'lib/tec_doc/article.rb', line 6 def scope @scope end |
#search_number ⇒ Object
Returns the value of attribute search_number.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def search_number @search_number end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/tec_doc/article.rb', line 3 def state @state end |
Class Method Details
.all(options) ⇒ Array<TecDoc::Article>
All articles by linked vehicle and brand number, generic article and assembly group
42 43 44 45 46 47 48 49 50 |
# File 'lib/tec_doc/article.rb', line 42 def self.all() = { :lang => I18n.locale.to_s, :country => TecDoc.client.country }.merge() TecDoc.client.request(:get_article_ids3, ).map do |attributes| new(attributes, ) end end |
.all_with_details(options) ⇒ Array<TecDoc::Article>
All requested articles detail information
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tec_doc/article.rb', line 64 def self.all_with_details() = { :lang => I18n.locale.to_s, :country => TecDoc.client.country, :attributs => true, :ean_numbers => true, :info => true, :oe_numbers => true, :usage_numbers => true, :article_id => { :array => { :ids => .delete(:ids) } } }.merge() TecDoc.client.request(:get_direct_articles_by_ids2, ).map do |attributes| new(attributes, ) end end |
.search(options = {}) ⇒ Array<TecDoc::Article>
Find article by all number types and brand number and generic article id.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tec_doc/article.rb', line 19 def self.search( = {}) = { :country => TecDoc.client.country, :lang => I18n.locale.to_s, :number_type => 10, :search_exact => 1, :sort_type => 1 }.merge() TecDoc.client.request(:get_article_direct_search_all_numbers2, ).map do |attributes| new(attributes, ) end end |
Instance Method Details
#attributes ⇒ Object
140 141 142 143 144 |
# File 'lib/tec_doc/article.rb', line 140 def attributes @attributes ||= article_details[:article_attributes].map do |attrs| ArticleAttribute.new(attrs) end end |
#brand ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/tec_doc/article.rb', line 119 def brand unless defined?(@brand) @brand = Brand.new @brand.number = brand_number @brand.name = brand_name end @brand end |
#documents ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/tec_doc/article.rb', line 128 def documents @documents ||= ArticleDocument.all({ :lang => scope[:lang], :country => scope[:country], :article_id => id }) end |
#ean_number ⇒ Object
146 147 148 |
# File 'lib/tec_doc/article.rb', line 146 def ean_number @ean_number ||= article_details[:ean_number].map(&:values).flatten.first end |
#information ⇒ Object
160 161 162 |
# File 'lib/tec_doc/article.rb', line 160 def information @information ||= direct_article_data_en[:article_info] end |
#linked_manufacturers ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/tec_doc/article.rb', line 164 def linked_manufacturers unless @linked_manufacturers response = TecDoc.client.request(:get_article_linked_all_linking_target_manufacturer, { :country => scope[:country], :linking_target_type => "C", :article_id => id }) @linked_manufacturers = response.map do |attrs| VehicleManufacturer.new(attrs) end end @linked_manufacturers end |
#linked_targets ⇒ Object
Array with all linked target vehicles with article link id If request entity is too large, we have to request linked targets by manufacturers
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/tec_doc/article.rb', line 181 def linked_targets unless @linked_targets = { :lang => scope[:lang], :country => scope[:country], :linking_target_type => "C", :linking_target_id => -1, :article_id => id } begin @linked_targets = TecDoc.client.request(:get_article_linked_all_linking_target_2, ) rescue @linked_targets = linked_manufacturers.inject([]) do |result, manufacturer| [:linking_target_manu_id] = manufacturer.id result += TecDoc.client.request(:get_article_linked_all_linking_target_2, ) end end end @linked_targets end |
#linked_vehicle_ids ⇒ Object
202 203 204 |
# File 'lib/tec_doc/article.rb', line 202 def linked_vehicle_ids @linked_vehicle_ids ||= linked_targets.map{ |attrs| attrs[:linking_target_id].to_i }.uniq end |
#linked_vehicles(options = {}) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/tec_doc/article.rb', line 206 def linked_vehicles( = {}) unless @linked_vehicles batch_list = linked_vehicle_ids.each_slice(25).to_a # Response from all batches response = batch_list.inject([]) do |result, long_list| result += TecDoc.client.request(:get_vehicle_by_ids_2, {:car_ids => { :array => {:ids => long_list} }, :lang => scope[:lang], :country => scope[:country], :country_user_setting => scope[:country], :countries_car_selection => scope[:country], :motor_codes => true, :axles => false, :cabs => false, :secondary_types => false, :vehicle_details2 => true, :vehicle_terms => false, :wheelbases => false }) result end @linked_vehicles = response.map do |attrs| details = (attrs[:vehicle_details2] || {}) vehicle = Vehicle.new vehicle.id = attrs[:car_id].to_i vehicle.name = "#{details[:manu_name]} - #{details[:model_name]} - #{details[:type_name]}" vehicle.power_hp_from = details[:power_hp].to_i vehicle.power_kw_from = details[:power_kw].to_i vehicle.cylinder_capacity = details[:cylinder_capacity_ccm].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.motor_codes = attrs[:motor_codes].map { |mc| mc[:motor_code] } vehicle end end @linked_vehicles end |
#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 |
#oe_numbers ⇒ Object
150 151 152 153 154 |
# File 'lib/tec_doc/article.rb', line 150 def oe_numbers @oe_numbers ||= article_details[:oen_numbers].map do |attrs| ArticleOENumber.new(attrs) end end |
#thumbnails ⇒ Object
136 137 138 |
# File 'lib/tec_doc/article.rb', line 136 def thumbnails @thumbnails ||= ArticleThumbnail.all(:article_id => id) end |
#trade_numbers ⇒ Object
156 157 158 |
# File 'lib/tec_doc/article.rb', line 156 def trade_numbers @trade_numbers ||= article_details[:usage_numbers].map(&:values).flatten.join(", ") end |