Class: TecDoc::Vehicle

Inherits:
Object
  • Object
show all
Defined in:
lib/tec_doc/vehicle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#article_link_idObject

Returns the value of attribute article_link_id.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def article_link_id
  @article_link_id
end

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def attributes
  @attributes
end

#cylinder_capacityObject

Returns the value of attribute cylinder_capacity.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def cylinder_capacity
  @cylinder_capacity
end

#date_of_construction_fromObject

Returns the value of attribute date_of_construction_from.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def date_of_construction_from
  @date_of_construction_from
end

#date_of_construction_toObject

Returns the value of attribute date_of_construction_to.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def date_of_construction_to
  @date_of_construction_to
end

#first_countryObject

Returns the value of attribute first_country.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def first_country
  @first_country
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def id
  @id
end

#linkedObject

Returns the value of attribute linked.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def linked
  @linked
end

#manu_idObject

Returns the value of attribute manu_id.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def manu_id
  @manu_id
end

#mod_idObject

Returns the value of attribute mod_id.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def mod_id
  @mod_id
end

#motor_codesObject

Returns the value of attribute motor_codes.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def motor_codes
  @motor_codes
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def name
  @name
end

#power_hp_fromObject

Returns the value of attribute power_hp_from.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def power_hp_from
  @power_hp_from
end

#power_hp_toObject

Returns the value of attribute power_hp_to.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def power_hp_to
  @power_hp_to
end

#power_kw_fromObject

Returns the value of attribute power_kw_from.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def power_kw_from
  @power_kw_from
end

#power_kw_toObject

Returns the value of attribute power_kw_to.



3
4
5
# File 'lib/tec_doc/vehicle.rb', line 3

def power_kw_to
  @power_kw_to
end

Class Method Details

.all(options = {}) ⇒ Array<TecDoc::VehicleManufacturer>

Find vehicles for simplified selection with motor codes

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :car_type (Integer)

    vehicle type (1: Passenger car, 2: Commercial vehicle, 3: Light commercial)

  • :countries_car_selection (String)

    country code according to ISO 3166

  • :country_group_flag (TrueClass, FalseClass)

    country group selection

  • :country_user_setting (String)

    country for article assignments, country code according to assignments ISO 3166 (optional)

  • :favoured_list (Integer, NilClass)

    simplified vehicle selection (1: first list selection, 0: rest)

  • :lang (String)

    language code according to ISO 639

  • :linked (TrueClass, FalseClass)

    selection with/without article assignments (false: all, true: only linked articles)

  • :manu_id (Integer)

    manufacturer ID

  • :mod_id (Integer)

    vehicle ID

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tec_doc/vehicle.rb', line 33

def self.all(options = {})
  options = {
    :car_type => 1,
    :countries_car_selection => TecDoc.client.country,
    :country_group_flag => false,
    :favoured_list => 1,
    :lang => I18n.locale.to_s,
    :linked => false
  }.merge(options)
  response = TecDoc.client.request(:get_vehicle_simplified_selection4, options)
  response.map do |attributes|
    vehicle = new
    car_attributes = attributes[:car_details]
    if car_attributes
      vehicle.manu_id                   = options[:manu_id].to_i
      vehicle.mod_id                    = options[:mod_id].to_i
      vehicle.id                        = car_attributes[:car_id].to_i
      vehicle.name                      = car_attributes[:car_name].to_s
      vehicle.cylinder_capacity         = car_attributes[:cylinder_capacity].to_i
      vehicle.first_country             = car_attributes[:first_country].to_s
      vehicle.linked                    = car_attributes[:linked]
      vehicle.power_hp_from             = car_attributes[:power_hp_from].to_i
      vehicle.power_hp_to               = car_attributes[:power_hp_to].to_i
      vehicle.power_kw_from             = car_attributes[:power_kw_from].to_i
      vehicle.power_kw_to               = car_attributes[:power_kw_to].to_i
      vehicle.date_of_construction_from = DateParser.new(car_attributes[:year_of_constr_from]).to_date
      vehicle.date_of_construction_to   = DateParser.new(car_attributes[:year_of_constr_to]).to_date
    end
    vehicle.motor_codes = attributes[:motor_codes].map { |mc| mc[:motor_code] }
    vehicle
  end
end

.find(options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tec_doc/vehicle.rb', line 66

def self.find(options = {})
  id = options.delete(:id)
  options = {
    :car_ids => { :array => { :ids => [id] } },
    :countries_car_selection => TecDoc.client.country,
    :country_user_setting => TecDoc.client.country,
    :country => TecDoc.client.country,
    :lang => TecDoc.client.country,
    :axles => false,
    :cabs => false,
    :country_group_flag => false,
    :motor_codes => true,
    :vehicle_details_2 => false,
    :vehicle_terms => true
  }.merge(options)
  response = TecDoc.client.request(:get_vehicle_by_ids_2, options)
  if attrs = response.first
    details  = attrs[:vehicle_details]  || {}
    terms    = attrs[:vehicle_terms]    || {}
    vehicle  = new
    vehicle.id                        = attrs[:car_id].to_i
    vehicle.name                      = terms[:car_type].to_s
    vehicle.cylinder_capacity         = details[:ccm_tech].to_i
    vehicle.power_hp_from             = details[:power_hp_from].to_i
    vehicle.power_hp_to               = details[:power_hp_to].to_i
    vehicle.power_kw_from             = details[:power_kw_from].to_i
    vehicle.power_kw_to               = details[:power_kw_to].to_i
    vehicle.date_of_construction_from = DateParser.new(details[:year_of_constr_from]).to_date
    vehicle.date_of_construction_to   = DateParser.new(details[:year_of_constr_to]).to_date
    vehicle.manu_id                   = details[:manu_id].to_i
    vehicle.mod_id                    = details[:mod_id].to_i
    vehicle.motor_codes = attrs[:motor_codes].map { |mc| mc[:motor_code] }
    vehicle
  else
    nil
  end
end

Instance Method Details

#assembly_groups(options = {}) ⇒ Object

Vehicle linked assembly parent groups



113
114
115
116
117
118
119
# File 'lib/tec_doc/vehicle.rb', line 113

def assembly_groups(options = {})
  options.merge!({
    :linking_target_type => "C",
    :linking_target_id => id,
  })
  AssemblyGroup.all(options)
end