Class: RichSnippet::Offer

Inherits:
Thing
  • Object
show all
Defined in:
app/models/rich_snippet/offer.rb

Instance Method Summary collapse

Methods inherited from Thing

#array_json, #module, #name, #type

Instance Method Details

#to_json(render_childs = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/rich_snippet/offer.rb', line 12

def to_json(render_childs = false)
  {
    "@context": "http://schema.org",
    "@type": "Offer",
    name: name,
    image: image ? image.binary_url : '',
    description: description,
    url: url,
    availability: {
      '@context': "http://schema.org",
      '@type': "ItemAvailability",
      description: availability
    },
    inventoryLevel: inventory_level,
    availabilityStarts: availability_starts,
    availabilityEnds: availability_ends,
    price: price,
    priceCurrency: price_currency,
    itemCondition: "https://schema.org/#{item_condition}Condition",
    seller: seller ? seller.to_json : nil
  }.delete_if { |k, v| !v.present? }
end

#warningsObject



35
36
37
38
39
# File 'app/models/rich_snippet/offer.rb', line 35

def warnings
  warns = []
  warns << "Price in the form xx.yy" if price.contains(',')
  return warns
end