reviewed_braai 0.0.2 → 0.0.3
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.
@@ -44,5 +44,26 @@ module ReviewedBraai
|
|
44
44
|
super(error)
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
class ManufacturerSpecNotFound < TagRenderError
|
49
|
+
def initialize(error={})
|
50
|
+
error = { error_message: "Manufacturer Spec Not Found" }.merge!(error)
|
51
|
+
super(error)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class RawScoreNotFound < TagRenderError
|
56
|
+
def initialize(error={})
|
57
|
+
error = { error_message: "Raw Score Not Found" }.merge!(error)
|
58
|
+
super(error)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class BrandNotFound < TagRenderError
|
63
|
+
def initialize(error={})
|
64
|
+
error = { error_message: "Brand Not Found" }.merge!(error)
|
65
|
+
super(error)
|
66
|
+
end
|
67
|
+
end
|
47
68
|
end
|
48
69
|
end
|
@@ -6,6 +6,20 @@ module ReviewedBraai
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
class ProductVanity < ReviewedBraai::Handlers::Base
|
10
|
+
def perform
|
11
|
+
attachment = match_attachment_by_tag(primary_product.attachments, "vanity")
|
12
|
+
::ReviewedBraai::Attachment.new(attachment).render
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ProductBrandMethod < ReviewedBraai::Handlers::Base
|
17
|
+
def perform
|
18
|
+
brand = match_brand
|
19
|
+
brand.send(matches[1])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
class ProductAttachmentById < ReviewedBraai::Handlers::Base
|
10
24
|
def perform
|
11
25
|
attachment = match_attachment(primary_product.attachments, :id, matches[1])
|
@@ -20,6 +34,18 @@ module ReviewedBraai
|
|
20
34
|
end
|
21
35
|
end
|
22
36
|
|
37
|
+
class ProductManufacturerSpec < ReviewedBraai::Handlers::Base
|
38
|
+
def perform
|
39
|
+
match_manufacturer_spec(matches[1])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ProductRawScore < ReviewedBraai::Handlers::Base
|
44
|
+
def perform
|
45
|
+
match_raw_score(matches[1])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
23
49
|
class ProductsMethod < ReviewedBraai::Handlers::Base
|
24
50
|
def perform
|
25
51
|
product = match_product(:id, matches[1])
|
@@ -27,6 +53,22 @@ module ReviewedBraai
|
|
27
53
|
end
|
28
54
|
end
|
29
55
|
|
56
|
+
class ProductsVanity < ReviewedBraai::Handlers::Base
|
57
|
+
def perform
|
58
|
+
product = match_product(:id, matches[1])
|
59
|
+
attachment = match_attachment_by_tag(product.attachments, "vanity")
|
60
|
+
::ReviewedBraai::Attachment.new(attachment).render
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class ProductsBrandMethod < ReviewedBraai::Handlers::Base
|
65
|
+
def perform
|
66
|
+
product = match_product(:id, matches[1])
|
67
|
+
brand = match_brand(product)
|
68
|
+
brand.send(matches[2])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
30
72
|
class ProductsAttachmentById < ReviewedBraai::Handlers::Base
|
31
73
|
def perform
|
32
74
|
product = match_product(:id, matches[1])
|
@@ -42,5 +84,19 @@ module ReviewedBraai
|
|
42
84
|
::ReviewedBraai::Attachment.new(attachment).render
|
43
85
|
end
|
44
86
|
end
|
87
|
+
|
88
|
+
class ProductsManufacturerSpec < ReviewedBraai::Handlers::Base
|
89
|
+
def perform
|
90
|
+
product = match_product(:id, matches[1])
|
91
|
+
match_manufacturer_spec(product, matches[2])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class ProductsRawScore < ReviewedBraai::Handlers::Base
|
96
|
+
def perform
|
97
|
+
product = match_product(:id, matches[1])
|
98
|
+
match_raw_score(product, matches[2])
|
99
|
+
end
|
100
|
+
end
|
45
101
|
end
|
46
102
|
end
|
@@ -2,10 +2,19 @@ module ReviewedBraai
|
|
2
2
|
module Helpers
|
3
3
|
|
4
4
|
def primary_product
|
5
|
-
|
5
|
+
if product = source.primary_product
|
6
|
+
product
|
7
|
+
else
|
6
8
|
raise ::ReviewedBraai::TagRenderError::ProductNotFound.new(default_args)
|
7
9
|
end
|
8
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def match_brand(product = source.primary_product)
|
13
|
+
if brand = product.brand
|
14
|
+
brand
|
15
|
+
else
|
16
|
+
raise ::ReviewedBraai::TagRenderError::BrandNotFound.new(default_args)
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
def match_attachment(attachments = source.attachments, attr, match)
|
@@ -16,6 +25,30 @@ module ReviewedBraai
|
|
16
25
|
end
|
17
26
|
end
|
18
27
|
|
28
|
+
def match_attachment_by_tag(attachments = source.attachments, tag)
|
29
|
+
if attachment = attachments.find { |a| a.tags.include?(tag) }
|
30
|
+
attachment
|
31
|
+
else
|
32
|
+
raise ::ReviewedBraai::TagRenderError::AttachmentNotFound.new(default_args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def match_manufacturer_spec(product = source.primary_product, name)
|
37
|
+
if spec = product.manufacturer_specs[name]
|
38
|
+
spec
|
39
|
+
else
|
40
|
+
raise ::ReviewedBraai::TagRenderError::ManufacturerSpecNotFound.new(default_args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def match_raw_score(product = source.primary_product, name)
|
45
|
+
if score = product.raw_scores[name] && product.raw_scores[name]["value"]
|
46
|
+
return score
|
47
|
+
else
|
48
|
+
raise ::ReviewedBraai::TagRenderError::RawScoreNotFound.new(default_args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
19
52
|
def match_product(products = source.products, attr, match)
|
20
53
|
if product = products.find { |a| a.send(attr) == match }
|
21
54
|
product
|
@@ -1,12 +1,20 @@
|
|
1
1
|
module ReviewedBraai
|
2
2
|
module Matchers
|
3
3
|
module Product
|
4
|
+
Braai::Template.map(/({{\s*product\.vanity\s*}})/i, ReviewedBraai::Handlers::ProductVanity)
|
4
5
|
Braai::Template.map(/({{\s*product\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ProductMethod)
|
6
|
+
Braai::Template.map(/({{\s*product\.brand\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ProductBrandMethod)
|
5
7
|
Braai::Template.map(/({{\s*product.attachments\((\w+)\)\s*}})/i, ReviewedBraai::Handlers::ProductAttachmentById)
|
6
8
|
Braai::Template.map(/({{\s*product.attachments\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductAttachmentByName)
|
9
|
+
Braai::Template.map(/({{\s*product.manufacturer_specs\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductManufacturerSpec)
|
10
|
+
Braai::Template.map(/({{\s*product.raw_scores\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductRawScore)
|
11
|
+
Braai::Template.map(/({{\s*products\((\w+)\)\.vanity\s*}})/i, ReviewedBraai::Handlers::ProductsVanity)
|
7
12
|
Braai::Template.map(/({{\s*products\((\w+)\)\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ProductsMethod)
|
13
|
+
Braai::Template.map(/({{\s*products\((\w+)\)\.brand\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ProductsBrandMethod)
|
8
14
|
Braai::Template.map(/({{\s*products\((\w+)\)\.attachments\((\w+)\)\s*}})/i, ReviewedBraai::Handlers::ProductsAttachmentById)
|
9
15
|
Braai::Template.map(/({{\s*products\((\w+)\)\.attachments\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductsAttachmentByName)
|
16
|
+
Braai::Template.map(/({{\s*products\((\w+)\)\.manufacturer_specs\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductsManufacturerSpec)
|
17
|
+
Braai::Template.map(/({{\s*products\((\w+)\)\.raw_scores\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductsRawScore)
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|