Class: BetterSeo::StructuredData::Product
- Inherits:
-
Base
- Object
- Base
- BetterSeo::StructuredData::Product
show all
- Defined in:
- lib/better_seo/structured_data/product.rb
Constant Summary
collapse
- AVAILABILITY_MAPPING =
{
"InStock" => "https://schema.org/InStock",
"OutOfStock" => "https://schema.org/OutOfStock",
"PreOrder" => "https://schema.org/PreOrder",
"Discontinued" => "https://schema.org/Discontinued",
"LimitedAvailability" => "https://schema.org/LimitedAvailability"
}.freeze
Instance Attribute Summary
Attributes inherited from Base
#properties, #type
Instance Method Summary
collapse
Methods inherited from Base
#get, #set, #to_h, #to_json, #to_script_tag, #valid?, #validate!
Constructor Details
#initialize(**properties) ⇒ Product
Returns a new instance of Product.
14
15
16
|
# File 'lib/better_seo/structured_data/product.rb', line 14
def initialize(**properties)
super("Product", **properties)
end
|
Instance Method Details
#aggregate_rating(rating_value:, review_count:, best_rating: 5, worst_rating: 1) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/better_seo/structured_data/product.rb', line 56
def aggregate_rating(rating_value:, review_count:, best_rating: 5, worst_rating: 1)
rating = {
"@type" => "AggregateRating",
"ratingValue" => rating_value,
"reviewCount" => review_count,
"bestRating" => best_rating,
"worstRating" => worst_rating
}
set(:aggregateRating, rating)
end
|
#brand(value) ⇒ Object
30
31
32
|
# File 'lib/better_seo/structured_data/product.rb', line 30
def brand(value)
set(:brand, value)
end
|
#description(value) ⇒ Object
22
23
24
|
# File 'lib/better_seo/structured_data/product.rb', line 22
def description(value)
set(:description, value)
end
|
#gtin(value) ⇒ Object
38
39
40
|
# File 'lib/better_seo/structured_data/product.rb', line 38
def gtin(value)
set(:gtin, value)
end
|
#image(value) ⇒ Object
26
27
28
|
# File 'lib/better_seo/structured_data/product.rb', line 26
def image(value)
set(:image, value)
end
|
#mpn(value) ⇒ Object
42
43
44
|
# File 'lib/better_seo/structured_data/product.rb', line 42
def mpn(value)
set(:mpn, value)
end
|
#name(value) ⇒ Object
18
19
20
|
# File 'lib/better_seo/structured_data/product.rb', line 18
def name(value)
set(:name, value)
end
|
#offers(value) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/better_seo/structured_data/product.rb', line 46
def offers(value)
if value.is_a?(Array)
set(:offers, value.map { |v| build_offer(v) })
elsif value.is_a?(Hash)
set(:offers, build_offer(value))
else
set(:offers, value)
end
end
|
#review(author:, rating_value:, review_body: nil, date_published: nil) ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/better_seo/structured_data/product.rb', line 67
def review(author:, rating_value:, review_body: nil, date_published: nil)
review_data = build_review(
author: author,
rating_value: rating_value,
review_body: review_body,
date_published: date_published
)
set(:review, review_data)
end
|
#reviews(reviews_array) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/better_seo/structured_data/product.rb', line 77
def reviews(reviews_array)
reviews_data = reviews_array.map do |review_hash|
build_review(
author: review_hash[:author],
rating_value: review_hash[:rating_value],
review_body: review_hash[:review_body],
date_published: review_hash[:date_published]
)
end
set(:review, reviews_data)
end
|
#sku(value) ⇒ Object
34
35
36
|
# File 'lib/better_seo/structured_data/product.rb', line 34
def sku(value)
set(:sku, value)
end
|