Class: AdfBuilder::Vehicles

Inherits:
Object
  • Object
show all
Defined in:
lib/adf_builder/vehicles/vehicles.rb

Constant Summary collapse

VALID_PARAMETERS =
{
  vehicle: [:interest, :status],
  odometer: [:status, :units],
  imagetag: [:width, :height, :alttext],
}
VALID_VALUES =
{
  vehicle: {
    interest: %w[buy lease sell trade-in test-drive],
    status: %w[new used]
  },
  odometer: {
    status: %w[unknown rolledover replaced original],
    units: %w[km mi]
  },
  imagetag: {
    width: true,
    height: true,
    alttext: true
  }
}
FREE_TEXT_OPTIONAL_TAGS =
[:year, :make, :model, :vin, :stock,
:trim, :doors, :bodystyle, :transmission, :pricecomments, :comments]
CONDITIONS =
%w[excellent good fair poor unknown]

Instance Method Summary collapse

Constructor Details

#initialize(prospect) ⇒ Vehicles

Returns a new instance of Vehicles.



30
31
32
33
34
# File 'lib/adf_builder/vehicles/vehicles.rb', line 30

def initialize(prospect)
  @prospect = prospect
  @color_combinations = []
  @prices = []
end

Instance Method Details

#add(year, make, model, params = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/adf_builder/vehicles/vehicles.rb', line 53

def add(year, make, model, params={})
  vehicle = Ox::Element.new('vehicle')

  params.merge!({valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS})
  AdfBuilder::Builder.update_params(vehicle, :vehicle, params)

  vehicle << (Ox::Element.new('year') << year.to_s)
  vehicle << (Ox::Element.new('make') << make)
  vehicle << (Ox::Element.new('model') << model)

  @prospect << vehicle
end

#add_color_combination(v_index, interior_color, exterior_color, preference) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/adf_builder/vehicles/vehicles.rb', line 36

def add_color_combination(v_index, interior_color, exterior_color, preference)
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', v_index)
  if valid
    cc = ColorCombinations.new(vehicle)
    cc.add(interior_color, exterior_color, preference)
    @color_combinations.push(cc)
  end
end

#add_comments(index, value) ⇒ Object



116
117
118
119
120
121
# File 'lib/adf_builder/vehicles/vehicles.rb', line 116

def add_comments(index, value)
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', index)
  if valid
    AdfBuilder::Builder.update_node(vehicle, 'comments', value)
  end
end

#add_id(index, value, source = nil, sequence = 1) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/adf_builder/vehicles/vehicles.rb', line 100

def add_id(index, value, source=nil, sequence=1)
  if @prospect.locate("vehicle").empty? or @prospect.vehicle(index).nil?
    false
  else
    Id.new.add(@prospect.vehicle(index), value, source, sequence)
  end
end

#add_price(index, value, params = {}) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/adf_builder/vehicles/vehicles.rb', line 108

def add_price(index, value, params={})
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', index)
  if valid
    price = Price.new(vehicle, value, params)
    @prices.push(price)
  end
end

#color_combination(index) ⇒ Object



45
46
47
# File 'lib/adf_builder/vehicles/vehicles.rb', line 45

def color_combination(index)
  @color_combinations[index]
end

#price(index) ⇒ Object



49
50
51
# File 'lib/adf_builder/vehicles/vehicles.rb', line 49

def price(index)
  @prices[index]
end

#update_condition(index, value) ⇒ Object



74
75
76
77
78
79
# File 'lib/adf_builder/vehicles/vehicles.rb', line 74

def update_condition(index, value)
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', index)
  if valid and CONDITIONS.include? value
    AdfBuilder::Builder.update_node(vehicle, 'condition', value)
  end
end

#update_imagetag(index, value, params = {}) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/adf_builder/vehicles/vehicles.rb', line 81

def update_imagetag(index, value, params={})
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', index)
  if valid
    params.merge!({valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS})
    AdfBuilder::Builder.update_node(vehicle, 'imagetag', value, params)
  end
end

#update_odometer(index, value, params = {}) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/adf_builder/vehicles/vehicles.rb', line 66

def update_odometer(index, value, params={})
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', index)
  if valid
    params.merge!({valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS})
    AdfBuilder::Builder.update_node(vehicle, 'odometer', value, params)
  end
end

#update_tags_with_free_text(index, tags) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/adf_builder/vehicles/vehicles.rb', line 89

def update_tags_with_free_text(index, tags)
  valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect,'vehicle', index)
  if valid
    tags.each do |key, value|
      if FREE_TEXT_OPTIONAL_TAGS.include? key.to_sym
        AdfBuilder::Builder.update_node(vehicle, key, value)
      end
    end
  end
end