reviewed_braai 0.0.3 → 0.0.4
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.
@@ -3,17 +3,12 @@ module ReviewedBraai
|
|
3
3
|
class Base
|
4
4
|
include ReviewedBraai::Helpers
|
5
5
|
|
6
|
-
attr_accessor :template, :key, :matches
|
6
|
+
attr_accessor :template, :key, :matches
|
7
7
|
|
8
8
|
class << self
|
9
9
|
|
10
10
|
def call(template, key, matches)
|
11
|
-
|
12
|
-
handler = self.new(template, key, matches)
|
13
|
-
rescue => e
|
14
|
-
return rescue_from_error(key)
|
15
|
-
end
|
16
|
-
|
11
|
+
handler = self.new(template, key, matches)
|
17
12
|
handler.safe_perform
|
18
13
|
end
|
19
14
|
|
@@ -26,7 +21,6 @@ module ReviewedBraai
|
|
26
21
|
@template = template
|
27
22
|
@key = key
|
28
23
|
@matches = matches
|
29
|
-
@source = extract_source(template)
|
30
24
|
end
|
31
25
|
|
32
26
|
def safe_perform
|
@@ -41,13 +35,6 @@ module ReviewedBraai
|
|
41
35
|
"<!-- #{key} -->"
|
42
36
|
end
|
43
37
|
|
44
|
-
def extract_source(template)
|
45
|
-
unless source = template.attributes[:source]
|
46
|
-
raise ::ReviewedBraai::TagRenderError::SourceNotFound.new(default_args)
|
47
|
-
end
|
48
|
-
return source
|
49
|
-
end
|
50
|
-
|
51
38
|
def rescue_from_error(key)
|
52
39
|
self.class.rescue_from_error(key)
|
53
40
|
end
|
@@ -2,14 +2,14 @@ module ReviewedBraai
|
|
2
2
|
module Helpers
|
3
3
|
|
4
4
|
def primary_product
|
5
|
-
if product =
|
5
|
+
if product = template.attributes[:article].primary_product
|
6
6
|
product
|
7
7
|
else
|
8
8
|
raise ::ReviewedBraai::TagRenderError::ProductNotFound.new(default_args)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def match_brand(product =
|
12
|
+
def match_brand(product = template.attributes[:article].primary_product)
|
13
13
|
if brand = product.brand
|
14
14
|
brand
|
15
15
|
else
|
@@ -17,7 +17,10 @@ module ReviewedBraai
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def match_attachment(attachments =
|
20
|
+
def match_attachment(attachments = nil, attr, match)
|
21
|
+
unless attachments
|
22
|
+
attachments = all_attachments
|
23
|
+
end
|
21
24
|
if attachment = attachments.find { |a| a.send(attr) == match }
|
22
25
|
attachment
|
23
26
|
else
|
@@ -25,7 +28,10 @@ module ReviewedBraai
|
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
|
-
def match_attachment_by_tag(attachments =
|
31
|
+
def match_attachment_by_tag(attachments = nil, tag)
|
32
|
+
unless attachments
|
33
|
+
attachments = all_attachments
|
34
|
+
end
|
29
35
|
if attachment = attachments.find { |a| a.tags.include?(tag) }
|
30
36
|
attachment
|
31
37
|
else
|
@@ -33,7 +39,7 @@ module ReviewedBraai
|
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
|
-
def match_manufacturer_spec(product =
|
42
|
+
def match_manufacturer_spec(product = template.attributes[:article].primary_product, name)
|
37
43
|
if spec = product.manufacturer_specs[name]
|
38
44
|
spec
|
39
45
|
else
|
@@ -41,7 +47,7 @@ module ReviewedBraai
|
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
44
|
-
def match_raw_score(product =
|
50
|
+
def match_raw_score(product = template.attributes[:article].primary_product, name)
|
45
51
|
if score = product.raw_scores[name] && product.raw_scores[name]["value"]
|
46
52
|
return score
|
47
53
|
else
|
@@ -49,7 +55,11 @@ module ReviewedBraai
|
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
52
|
-
def match_product(products =
|
58
|
+
def match_product(products = [], attr, match)
|
59
|
+
if products.empty?
|
60
|
+
art = template.attributes[:article]
|
61
|
+
products = art.products if art
|
62
|
+
end
|
53
63
|
if product = products.find { |a| a.send(attr) == match }
|
54
64
|
product
|
55
65
|
else
|
@@ -59,14 +69,23 @@ module ReviewedBraai
|
|
59
69
|
|
60
70
|
def all_attachments
|
61
71
|
attachments = []
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
72
|
+
#template.attributes.values.each do |source|
|
73
|
+
template.attributes.values.compact.each do |source|
|
74
|
+
if (source.is_a?(Array))
|
75
|
+
attachments += source.map {|x| x.attachments if x.attachments}.flatten
|
76
|
+
else
|
77
|
+
attachments += source.attachments if source.attachments
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# attachments.flatten! if attachments
|
81
|
+
# attachments.compact! if attachments
|
82
|
+
# attachments.uniq! if attachments
|
83
|
+
# attachments
|
84
|
+
attachments.flatten.compact.uniq
|
66
85
|
end
|
67
86
|
|
68
87
|
def default_args
|
69
|
-
{ key: key, parameters: { template: template, key: key, matches: matches
|
88
|
+
{ key: key, parameters: { template: template, key: key, matches: matches } }
|
70
89
|
end
|
71
90
|
end
|
72
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reviewed_braai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: braai
|
@@ -95,4 +95,3 @@ signing_key:
|
|
95
95
|
specification_version: 3
|
96
96
|
summary: Braai matchers for Reviewed.com
|
97
97
|
test_files: []
|
98
|
-
has_rdoc:
|