adf_builder 0.4.0 → 1.1.0

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.
@@ -1,123 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AdfBuilder
4
- class Vehicles
5
- VALID_PARAMETERS = {
6
- vehicle: %i[interest status],
7
- odometer: %i[status units],
8
- imagetag: %i[width height alttext]
9
- }.freeze
10
-
11
- VALID_VALUES = {
12
- vehicle: {
13
- interest: %w[buy lease sell trade-in test-drive],
14
- status: %w[new used]
15
- },
16
- odometer: {
17
- status: %w[unknown rolledover replaced original],
18
- units: %w[km mi]
19
- },
20
- imagetag: {
21
- width: true,
22
- height: true,
23
- alttext: true
24
- }
25
- }.freeze
26
-
27
- FREE_TEXT_OPTIONAL_TAGS = %i[year make model vin stock
28
- trim doors bodystyle transmission pricecomments comments].freeze
29
-
30
- CONDITIONS = %w[excellent good fair poor unknown].freeze
31
-
32
- def initialize(prospect)
33
- @prospect = prospect
34
- @color_combinations = []
35
- @prices = []
36
- end
37
-
38
- def add_color_combination(v_index, interior_color, exterior_color, preference)
39
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", v_index)
40
- return unless valid
41
-
42
- cc = ColorCombinations.new(vehicle)
43
- cc.add(interior_color, exterior_color, preference)
44
- @color_combinations.push(cc)
45
- end
46
-
47
- def color_combination(index)
48
- @color_combinations[index]
49
- end
50
-
51
- def price(index)
52
- @prices[index]
53
- end
54
-
55
- def add(year, make, model, params = {})
56
- vehicle = Ox::Element.new("vehicle")
57
-
58
- params.merge!({ valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS })
59
- AdfBuilder::Builder.update_params(vehicle, :vehicle, params)
60
-
61
- vehicle << (Ox::Element.new("year") << year.to_s)
62
- vehicle << (Ox::Element.new("make") << make)
63
- vehicle << (Ox::Element.new("model") << model)
64
-
65
- @prospect << vehicle
66
- end
67
-
68
- def update_odometer(index, value, params = {})
69
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", index)
70
- return unless valid
71
-
72
- params.merge!({ valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS })
73
- AdfBuilder::Builder.update_node(vehicle, "odometer", value, params)
74
- end
75
-
76
- def update_condition(index, value)
77
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", index)
78
- return unless valid && CONDITIONS.include?(value)
79
-
80
- AdfBuilder::Builder.update_node(vehicle, "condition", value)
81
- end
82
-
83
- def update_imagetag(index, value, params = {})
84
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", index)
85
- return unless valid
86
-
87
- params.merge!({ valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS })
88
- AdfBuilder::Builder.update_node(vehicle, "imagetag", value, params)
89
- end
90
-
91
- def update_tags_with_free_text(index, tags)
92
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", index)
93
- return unless valid
94
-
95
- tags.each do |key, value|
96
- AdfBuilder::Builder.update_node(vehicle, key, value) if FREE_TEXT_OPTIONAL_TAGS.include? key.to_sym
97
- end
98
- end
99
-
100
- def add_id(index, value, source = nil, sequence = 1)
101
- if @prospect.locate("vehicle").empty? || @prospect.vehicle(index).nil?
102
- false
103
- else
104
- Id.new.add(@prospect.vehicle(index), value, source, sequence)
105
- end
106
- end
107
-
108
- def add_price(index, value, params = {})
109
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", index)
110
- return unless valid
111
-
112
- price = Price.new(vehicle, value, params)
113
- @prices.push(price)
114
- end
115
-
116
- def add_comments(index, value)
117
- valid, vehicle = AdfBuilder::Builder.valid_child?(@prospect, "vehicle", index)
118
- return unless valid
119
-
120
- AdfBuilder::Builder.update_node(vehicle, "comments", value)
121
- end
122
- end
123
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AdfBuilder
4
- class Vendor
5
- def initialize(prospect)
6
- @vendor = Ox::Element.new("vendor")
7
- @contact = nil
8
- prospect << @vendor
9
- end
10
-
11
- attr_reader :contact
12
-
13
- def add(name, contact_name, opts = {})
14
- @vendor << (Ox::Element.new("vendorname") << name)
15
- @contact = Contact.new(@vendor, contact_name, opts)
16
- end
17
-
18
- def add_url(url)
19
- @vendor.remove_children(@vendor.url) if @vendor.locate("url").size.positive?
20
- @vendor << (Ox::Element.new("url") << url)
21
- end
22
-
23
- def add_id(index, value, source = nil, sequence = 1)
24
- if @prospect.locate("vendor").empty?
25
- false
26
- else
27
- Id.new.add(@prospect.vendor(index), value, source, sequence)
28
- end
29
- end
30
- end
31
- end