Class: SchemaCell

Inherits:
Cell::ViewModel
  • Object
show all
Defined in:
app/cells/schema_cell.rb

Overview

Schema.org for Hungryhub

Constant Summary collapse

PAGES =
%w[home restaurant].freeze
%w[home].freeze

Instance Method Summary collapse

Instance Method Details

#as_organizationObject



184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/cells/schema_cell.rb', line 184

def as_organization
  {
    "@context": 'https://schema.org',
    "@type": 'Organization',
    name: 'Hungry Hub',
    url: 'https://www.hungryhub.com',
    logo: URI.join(root_url, image_url('v2/logo_mobile.png')).to_s,
    contact_point: [
      customer_service_cp,
    ],
  }
end

#as_productObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/cells/schema_cell.rb', line 83

def as_product
  result = {
    "@context": 'https://schema.org/',
    "@type": 'Product',
    name: seo_cell.title,
    image: [
      model.image_cover_url(only_path: false),
      model.image_cover_url(only_path: false, width: 200, height: 200),
      model.image_cover_url(only_path: false, original: true),
    ],
    description: seo_cell.description,
    mpn: model.encrypted_id,
    brand: as_restaurant.except('@context'),
    sku: model.encrypted_id,
  }.merge(restaurant_aggregate_rating)

  review = single_restaurant_review

  result.merge!(review: review) if review.present?
  result.merge!(offers: product_offers) if model.allow_booking?

  result
end

#as_restaurantObject

requires Restaurant model



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/cells/schema_cell.rb', line 108

def as_restaurant
  {
    "@context": 'https://schema.org',
    "@type": 'Restaurant',
    name: seo_cell.title,
    description: seo_cell.description,
    acceptsReservations: model.allow_booking? && !model.date_offer_expired?(Date.restaurant_today(model)),
    hasMenu: true,
    servesCuisine: model.cuisines.join(', ').to_s,
    starRating: {
      "@type": 'Rating',
      ratingValue: review_filter.meta[:average].to_s,
      worstRating: '0',
      bestRating: '5',
    },
    address: {
      "@type": 'PostalAddress',
      streetAddress: model.address.to_s,
      addressCountry: model.country.alpha2,
    },
    openingHours: model.opening_hours.to_s,
    image: URI.join(root_url, model.image_cover_url(original: true, include_size: false)).to_s,
    video: restaurant_video(model),
    url: agreed_restaurant_url,
    telephone: AdminSetting.support_phones.join(', ').to_s,
    geo: {
      "@type": 'GeoCoordinates',
      latitude: model.lat,
      longitude: model.lng,
    },
    priceRange: model.price_range,
  }.merge(restaurant_aggregate_rating)
end

#as_serviceObject

requires Restaurant model



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/cells/schema_cell.rb', line 52

def as_service
  {
    "@context": 'https://schema.org',
    "@type": 'Service',
    serviceType: 'Restaurant Booking',
    provider: {
      "@type": 'Organization',
      name: 'Hungry Hub',
    },
    areaServed: 'World wide',
    availableChannel: {
      "@type": 'ServiceChannel',

      availableLanguage: MyLocaleManager.available_locales.map do |locale|
        {
          "@type": 'Language',
          identifier: locale.upcase,
        }
      end,

      service_url: agreed_restaurant_url,
    },
    termsOfService: AdminSetting.service_tnc_url,

    # review: featured_reviews.map do |review|
    #   service_review_schema(review)
    # end,

  }
end

#as_software_applicationObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/cells/schema_cell.rb', line 162

def as_software_application
  {
    "@context": 'https://schema.org',
    "@type": 'SoftwareApplication',
    name: 'Hungry Hub - Thailand Dining Offer App',
    operating_system: 'Android, iOS',
    application_category: 'Booking Service',
    aggregate_rating: {
      "@type": 'AggregateRating',
      worstRating: '0',
      bestRating: '5',
      ratingValue: '4.5',
      ratingCount: '673',
    },
    offers: {
      "@type": 'Offer',
      price: '0.00',
      price_currency: 'THB',
    },
  }
end

#as_websiteObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/cells/schema_cell.rb', line 142

def as_website
  {
    "@context": 'https://schema.org',
    "@type": 'WebSite',
    name: 'Hungry Hub',
    url: root_url,
    potentialAction: {
      "@type": 'SearchAction',
      target: 'https://www.hungryhub.com/en/restaurants/search.html?name={search_term_string}',
      "query-input": 'required name=search_term_string',
    },
    sameAs: [
      'http://www.facebook.com/HungryHub',
      'http://instagram.com/hungryhub_th',
      'https://www.linkedin.com/company/appservation/',
      'http://twitter.com/hungryhub',
    ],
  }
end

#customer_service_cpObject



197
198
199
200
201
202
203
204
205
206
# File 'app/cells/schema_cell.rb', line 197

def customer_service_cp
  phone = AdminSetting.support_phones&.to_sentence.to_s
  phone[0] = '+66' if phone[0] == '0'
  {
    "@type": 'ContactPoint',
    telephone: phone,
    contact_type: 'customer service',
    available_language: %w[English Thailand],
  }
end

#home_breadcrumbObject



19
20
21
22
23
24
25
26
27
# File 'app/cells/schema_cell.rb', line 19

def home_breadcrumb
  {
    name: 'Home',
    item: {
      "@type": 'WebSite',
      "@id": root_url,
    },
  }
end

#product_breadcrumbObject



40
41
42
43
44
45
46
47
48
49
# File 'app/cells/schema_cell.rb', line 40

def product_breadcrumb
  {
    name: seo_cell.title,
    item: {
      "@type": 'Product',
      "@id": agreed_restaurant_url,
      name: model.name,
    }.merge(restaurant_aggregate_rating),
  }
end

#restaurant_breadcrumbObject

requires Restaurant model



30
31
32
33
34
35
36
37
38
# File 'app/cells/schema_cell.rb', line 30

def restaurant_breadcrumb
  {
    name: seo_cell.title,
    item: {
      "@type": 'Restaurant',
      "@id": agreed_restaurant_url,
    },
  }
end