schema_dot_org 1.7.1 → 2.0

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +41 -43
  3. data/README.md +1 -1
  4. data/bin/tapioca +29 -0
  5. data/lib/schema_dot_org/aggregate_offer.rb +36 -0
  6. data/lib/schema_dot_org/contact_point.rb +31 -0
  7. data/lib/schema_dot_org/item_list.rb +37 -0
  8. data/lib/schema_dot_org/list_item.rb +30 -0
  9. data/lib/schema_dot_org/offer.rb +29 -0
  10. data/lib/schema_dot_org/organization.rb +22 -14
  11. data/lib/schema_dot_org/person.rb +10 -5
  12. data/lib/schema_dot_org/place.rb +0 -2
  13. data/lib/schema_dot_org/product.rb +37 -0
  14. data/lib/schema_dot_org/schema_type.rb +67 -0
  15. data/lib/schema_dot_org/search_action.rb +0 -2
  16. data/lib/schema_dot_org/web_site.rb +3 -6
  17. data/lib/schema_dot_org.rb +18 -55
  18. data/schema_dot_org.gemspec +6 -8
  19. data/test-script.rb +1 -4
  20. metadata +21 -60
  21. data/run-script +0 -2
  22. data/sorbet/config +0 -2
  23. data/sorbet/rbi/gems/activemodel.rbi +0 -262
  24. data/sorbet/rbi/gems/activesupport.rbi +0 -912
  25. data/sorbet/rbi/gems/concurrent-ruby.rbi +0 -1590
  26. data/sorbet/rbi/gems/i18n.rbi +0 -133
  27. data/sorbet/rbi/gems/rake.rbi +0 -644
  28. data/sorbet/rbi/gems/rspec-core.rbi +0 -1872
  29. data/sorbet/rbi/gems/rspec-expectations.rbi +0 -1123
  30. data/sorbet/rbi/gems/rspec-mocks.rbi +0 -1090
  31. data/sorbet/rbi/gems/rspec-support.rbi +0 -280
  32. data/sorbet/rbi/gems/rspec.rbi +0 -15
  33. data/sorbet/rbi/gems/thread_safe.rbi +0 -82
  34. data/sorbet/rbi/gems/tzinfo.rbi +0 -408
  35. data/sorbet/rbi/gems/validated_object.rbi +0 -60
  36. data/sorbet/rbi/sorbet-typed/lib/activemodel/all/activemodel.rbi +0 -597
  37. data/sorbet/rbi/sorbet-typed/lib/activesupport/>=6/activesupport.rbi +0 -36
  38. data/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +0 -1431
  39. data/sorbet/rbi/sorbet-typed/lib/minitest/all/minitest.rbi +0 -108
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125273e4c13ee100e668d7aad12d40379c51773968c50013fe21845fc2d60cb6
4
- data.tar.gz: e27714ef970a5320827c7250e504050c97d58a5d8a2acea7aa589a81797a4729
3
+ metadata.gz: 643f2d209ee7cac02447c46cc8f5c14682163dd171db5d3c1b5fdf84382a3eab
4
+ data.tar.gz: cab0857ac26be75638701893e328db0a93840a368b46df5e5e6a106ccb98f3be
5
5
  SHA512:
6
- metadata.gz: 7bb7ef8ca7d109793ebec2c79de1931855f7cff07f5751c5d7d6b7bc1a09ac4d431aa254c834f356e968ea4aae3f259765cf33e734701b836f69240cb7da6cb8
7
- data.tar.gz: 6894a06c5bad02000c1de3e2d4aa4171c18f76d417d82ce52b783bcb7ee90d315742d1b879b88a3f728515877b704b980b87e25b962bf85b706ee7f958e6344e
6
+ metadata.gz: 69e7822b9097e10d3a4d51053f32982fddde76ffcccd3f611474d08c6ef890dc31a16cd3bcf14d6420b592ff80fff756b8737f733a0e57c1ffcc0be925772025
7
+ data.tar.gz: 65e88820be2cdedb39aee20ca85bc14e1866b64a2737323076bba3d18d39184cc37b192edfbc65ba5ba1b194de0f9339fece13fb1e7fdd7d72e755bf3442e800
data/Gemfile.lock CHANGED
@@ -1,67 +1,65 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schema_dot_org (1.7.0)
5
- sorbet-runtime (>= 0.5.5890)
6
- validated_object (~> 2.1)
4
+ schema_dot_org (2.0)
5
+ validated_object (~> 2.2)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- activemodel (6.1.4)
12
- activesupport (= 6.1.4)
13
- activesupport (6.1.4)
10
+ activemodel (7.1.1)
11
+ activesupport (= 7.1.1)
12
+ activesupport (7.1.1)
13
+ base64
14
+ bigdecimal
14
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ connection_pool (>= 2.2.5)
17
+ drb
15
18
  i18n (>= 1.6, < 2)
16
19
  minitest (>= 5.1)
20
+ mutex_m
17
21
  tzinfo (~> 2.0)
18
- zeitwerk (~> 2.3)
19
- concurrent-ruby (1.1.9)
20
- diff-lcs (1.4.4)
21
- i18n (1.8.10)
22
+ base64 (0.1.1)
23
+ bigdecimal (3.1.4)
24
+ concurrent-ruby (1.2.2)
25
+ connection_pool (2.4.1)
26
+ diff-lcs (1.5.0)
27
+ drb (2.1.1)
28
+ ruby2_keywords
29
+ i18n (1.14.1)
22
30
  concurrent-ruby (~> 1.0)
23
- minitest (5.14.4)
24
- rake (13.0.5)
25
- rspec (3.10.0)
26
- rspec-core (~> 3.10.0)
27
- rspec-expectations (~> 3.10.0)
28
- rspec-mocks (~> 3.10.0)
29
- rspec-core (3.10.1)
30
- rspec-support (~> 3.10.0)
31
- rspec-expectations (3.10.1)
31
+ minitest (5.20.0)
32
+ mutex_m (0.1.2)
33
+ rake (13.0.6)
34
+ rspec (3.12.0)
35
+ rspec-core (~> 3.12.0)
36
+ rspec-expectations (~> 3.12.0)
37
+ rspec-mocks (~> 3.12.0)
38
+ rspec-core (3.12.2)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-expectations (3.12.3)
32
41
  diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.10.0)
34
- rspec-mocks (3.10.2)
42
+ rspec-support (~> 3.12.0)
43
+ rspec-mocks (3.12.6)
35
44
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.10.0)
37
- rspec-support (3.10.2)
38
- sorbet (0.5.6485)
39
- sorbet-static (= 0.5.6485)
40
- sorbet-runtime (0.5.6485)
41
- sorbet-static (0.5.6485-universal-darwin-14)
42
- sorbet-static (0.5.6485-universal-darwin-15)
43
- sorbet-static (0.5.6485-universal-darwin-16)
44
- sorbet-static (0.5.6485-universal-darwin-17)
45
- sorbet-static (0.5.6485-universal-darwin-18)
46
- sorbet-static (0.5.6485-universal-darwin-19)
47
- sorbet-static (0.5.6485-universal-darwin-20)
48
- sorbet-static (0.5.6485-x86_64-linux)
49
- tzinfo (2.0.4)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-support (3.12.1)
47
+ ruby2_keywords (0.0.5)
48
+ sorbet-runtime (0.5.10993)
49
+ tzinfo (2.0.6)
50
50
  concurrent-ruby (~> 1.0)
51
- validated_object (2.1.0)
51
+ validated_object (2.2.0)
52
52
  activemodel (>= 3.2.21)
53
53
  sorbet-runtime (>= 0.5.5890)
54
- zeitwerk (2.4.2)
55
54
 
56
55
  PLATFORMS
57
- ruby
56
+ arm64-darwin-22
58
57
 
59
58
  DEPENDENCIES
60
- bundler (~> 2)
61
- rake (>= 12.3.3)
62
- rspec (~> 3.0)
59
+ bundler (~> 2.4)
60
+ rake (~> 13.0)
61
+ rspec (~> 3.12)
63
62
  schema_dot_org!
64
- sorbet (>= 0.5.5890)
65
63
 
66
64
  BUNDLED WITH
67
- 2.2.15
65
+ 2.4.20
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # SchemaDotOrg
4
4
 
5
- Let's create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) with correct **syntax** and **semantics**,
5
+ Create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) with correct **syntax** and **semantics**,
6
6
  every single time. Good structured data [helps enhance a website's search result appearance](https://developers.google.com/search/docs/guides/enhance-site).
7
7
 
8
8
  > Google Search works hard to understand the content of a page. You can help us by providing explicit clues about the meaning of a page . . .
data/bin/tapioca ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'tapioca' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("tapioca", "tapioca")
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'schema_dot_org'
5
+ require 'schema_dot_org/offer'
6
+
7
+ # Model the Schema.org `Thing > Place`. See https://schema.org/Offer
8
+ #
9
+ module SchemaDotOrg
10
+ class AggregateOffer < SchemaType
11
+ attr_accessor :priceCurrency,
12
+ :highPrice,
13
+ :lowPrice,
14
+ :offerCount,
15
+ :offers
16
+
17
+ validates :lowPrice, type: Numeric
18
+ validates :highPrice, type: Numeric, allow_nil: true
19
+ validates :offerCount, type: String, allow_nil: true
20
+ validates :offers, type: Array, allow_nil: true
21
+
22
+ def _to_json_struct
23
+ {
24
+ "priceCurrency" => priceCurrency,
25
+ "lowPrice" => lowPrice,
26
+ "highPrice" => highPrice,
27
+ "offerCount" => offerCount,
28
+ "offers" => offers.map(&:to_json_struct)
29
+ }
30
+ end
31
+
32
+ def offers
33
+ @offers || []
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'schema_dot_org'
4
+
5
+
6
+ module SchemaDotOrg
7
+ # Model the Schema.org `ContactPoint`. See http://schema.org/ContactPoint
8
+ class ContactPoint < SchemaType
9
+ attr_accessor :telephone,
10
+ :contact_type,
11
+ :contact_option,
12
+ :area_served,
13
+ :available_language
14
+
15
+ validates :telephone, type: String, presence: true
16
+ validates :contact_type, type: String, presence: true
17
+ validates :contact_option, type: String, allow_nil: true
18
+ validates :area_served, type: Array, allow_nil: true
19
+ validates :available_language, type: Array, allow_nil: true
20
+
21
+ def _to_json_struct
22
+ {
23
+ 'telephone' => telephone,
24
+ 'contactType' => contact_type,
25
+ 'contactOption' => contact_option,
26
+ 'areaServed' => area_served,
27
+ 'availableLanguage' => available_language
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'schema_dot_org'
4
+
5
+ module SchemaDotOrg
6
+ # Model the Schema.org `ItemList`. See https://schema.org/ItemList
7
+ class ItemList < SchemaType
8
+ attr_accessor :itemListOrder,
9
+ :numberOfItems,
10
+ :url,
11
+ :image,
12
+ :itemListElement
13
+
14
+
15
+ validates :itemListElement, type: Array, presence: true
16
+ validates :itemListOrder, type: String, allow_nil: true
17
+ validates :numberOfItems, type: Integer, allow_nil: true
18
+
19
+ validates :url, type: String, allow_nil: true
20
+ validates :image, type: String, allow_nil: true
21
+
22
+
23
+ def _to_json_struct
24
+ {
25
+ 'itemListOrder' => itemListOrder,
26
+ 'numberOfItems' => numberOfItems,
27
+ 'url' => url,
28
+ 'image' => image,
29
+ 'itemListElement' => itemListElement.map(&:to_json_struct)
30
+ }
31
+ end
32
+
33
+ def itemListElement
34
+ @itemListElement || []
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'schema_dot_org'
4
+ require 'schema_dot_org/product'
5
+
6
+
7
+ module SchemaDotOrg
8
+ # Model the Schema.org `ItemListElement`. See https://schema.org/ItemListElement
9
+ class ListItem < SchemaType
10
+ attr_accessor :position, :item,
11
+ :url, :name, :image
12
+
13
+ validates :position, type: Integer, presence: true
14
+ validates :url, type: String, allow_nil: true
15
+ validates :name, type: String, allow_nil: true
16
+ validates :image, type: String, allow_nil: true
17
+
18
+ validates :item, type: Product, allow_nil: true
19
+
20
+ def _to_json_struct
21
+ {
22
+ 'position' => position,
23
+ 'url' => url,
24
+ 'name' => name,
25
+ 'image' => image,
26
+ 'item' => object_to_json_struct(item)
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'schema_dot_org'
5
+
6
+ # Model the Schema.org `Thing > Place`. See https://schema.org/Offer
7
+ #
8
+ module SchemaDotOrg
9
+ class Offer < SchemaType
10
+ attr_accessor :priceCurrency,
11
+ :price,
12
+ :availability,
13
+ :url
14
+
15
+ validates :priceCurrency, type: String
16
+ validates :price, type: Numeric
17
+ validates :availability, type: String, allow_nil: true
18
+ validates :url, type: String, allow_nil: true
19
+
20
+ def _to_json_struct
21
+ {
22
+ "price" => price,
23
+ "priceCurrency" => priceCurrency,
24
+ "availability" => availability,
25
+ "url" => url
26
+ }
27
+ end
28
+ end
29
+ end
@@ -1,10 +1,11 @@
1
- # typed: ignore
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'date'
5
4
  require 'schema_dot_org'
6
5
  require 'schema_dot_org/person'
7
6
  require 'schema_dot_org/place'
7
+ require 'schema_dot_org/contact_point'
8
+
8
9
 
9
10
  module SchemaDotOrg
10
11
  class Organization < SchemaType
@@ -15,28 +16,35 @@ module SchemaDotOrg
15
16
  :logo,
16
17
  :name,
17
18
  :url,
18
- :same_as
19
+ :same_as,
20
+ :contact_points
19
21
 
20
- validates :email, type: String
21
- validates :founder, type: SchemaDotOrg::Person
22
- validates :founding_date, type: Date
23
- validates :founding_location, type: SchemaDotOrg::Place
22
+ validates :email, type: String, allow_nil: true
23
+ validates :founder, type: SchemaDotOrg::Person, allow_nil: true
24
+ validates :founding_date, type: Date, allow_nil: true
25
+ validates :founding_location, type: SchemaDotOrg::Place, allow_nil: true
24
26
  validates :logo, type: String
25
27
  validates :name, type: String
26
28
  validates :url, type: String
27
29
  validates :same_as, type: Array, allow_nil: true
30
+ validates :contact_points, type: Array, allow_nil: true
28
31
 
29
32
  def _to_json_struct
30
33
  {
31
- 'name' => name,
32
- 'email' => email,
33
- 'url' => url,
34
- 'logo' => logo,
35
- 'founder' => founder.to_json_struct,
36
- 'foundingDate' => founding_date.to_s,
37
- 'foundingLocation' => founding_location.to_json_struct,
38
- 'sameAs' => same_as
34
+ "name" => name,
35
+ "email" => email,
36
+ "url" => url,
37
+ "logo" => logo,
38
+ "founder" => object_to_json_struct(founder),
39
+ "foundingDate" => founding_date.to_s,
40
+ "foundingLocation" => object_to_json_struct(founding_location),
41
+ "sameAs" => same_as,
42
+ "contactPoint" => contact_points.map(&:to_json_struct)
39
43
  }
40
44
  end
45
+
46
+ def contact_points
47
+ @contact_points || []
48
+ end
41
49
  end
42
50
  end
@@ -1,17 +1,22 @@
1
- # typed: ignore
2
1
  # frozen_string_literal: true
3
2
 
4
- require 'schema_dot_org'
5
3
 
6
4
  module SchemaDotOrg
7
5
  # Model the Schema.org `Person`. See http://schema.org/Person
8
6
  class Person < SchemaType
9
- attr_accessor :name
10
- validates :name, type: String, presence: true
7
+ attr_accessor :name,
8
+ :url,
9
+ :same_as
10
+
11
+ validates :name, type: String, presence: true
12
+ validates :url, type: String, allow_nil: true
13
+ validates :same_as, type: Array, allow_nil: true
11
14
 
12
15
  def _to_json_struct
13
16
  {
14
- 'name' => name
17
+ 'name' => name,
18
+ 'url' => url,
19
+ 'same_as' => same_as
15
20
  }
16
21
  end
17
22
  end
@@ -1,7 +1,5 @@
1
- # typed: ignore
2
1
  # frozen_string_literal: true
3
2
 
4
- require 'schema_dot_org'
5
3
 
6
4
  module SchemaDotOrg
7
5
  # Model the Schema.org `Thing > Place`. See http://schema.org/Place
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'schema_dot_org'
5
+ require 'schema_dot_org/aggregate_offer'
6
+
7
+ # Model the Schema.org `Thing > Place`. See https://schema.org/Product
8
+ #
9
+ module SchemaDotOrg
10
+ class Product < SchemaType
11
+ attr_accessor :name,
12
+ :url,
13
+ :description,
14
+ :image,
15
+ :offers
16
+
17
+ validates :name, type: String
18
+ validates :url, type: String
19
+ validates :description, type: String, allow_nil: true
20
+ validates :image, type: Array, allow_nil: true
21
+ validates :offers, type: SchemaDotOrg::AggregateOffer
22
+
23
+ def _to_json_struct
24
+ {
25
+ "name" => name,
26
+ "url" => url,
27
+ "description" => description,
28
+ "image" => image,
29
+ "offers" => offers.to_json_struct
30
+ }
31
+ end
32
+
33
+ def image
34
+ @image || []
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,67 @@
1
+ require 'json'
2
+ require 'validated_object'
3
+
4
+ module SchemaDotOrg
5
+ class SchemaType < ValidatedObject::Base
6
+ ROOT_ATTR = { "@context" => "http://schema.org" }.freeze
7
+ UNQUALIFIED_CLASS_NAME_REGEX = /([^:]+)$/
8
+
9
+
10
+ def to_s
11
+ json_string = to_json_ld(pretty: (!rails_production? && !ENV['SCHEMA_DOT_ORG_MINIFIED_JSON']))
12
+
13
+ # Mark as safe if we're in Rails
14
+ if json_string.respond_to?(:html_safe)
15
+ json_string.html_safe
16
+ else
17
+ json_string
18
+ end
19
+ end
20
+
21
+
22
+ def to_json_ld(pretty: false)
23
+ "<script type=\"application/ld+json\">\n" + to_json(pretty: pretty, as_root: true) + "\n</script>"
24
+ end
25
+
26
+
27
+ def to_json(pretty: false, as_root: false)
28
+ structure = as_root ? ROOT_ATTR.merge(to_json_struct) : to_json_struct
29
+
30
+ if pretty
31
+ JSON.pretty_generate(structure)
32
+ else
33
+ structure.to_json
34
+ end
35
+ end
36
+
37
+
38
+ # Use the class name to create the "@type" attribute.
39
+ # @return a hash structure representing json.
40
+ def to_json_struct
41
+ { "@type" => un_namespaced_classname }.merge(_to_json_struct.reject { |_, v| v.blank? })
42
+ end
43
+
44
+
45
+ def _to_json_struct
46
+ raise "For subclasses to implement"
47
+ end
48
+
49
+
50
+ # @return the classname without the module namespace.
51
+ def un_namespaced_classname
52
+ self.class.name =~ UNQUALIFIED_CLASS_NAME_REGEX
53
+ Regexp.last_match(1)
54
+ end
55
+
56
+ def object_to_json_struct(object)
57
+ return nil unless object
58
+ object.to_json_struct
59
+ end
60
+
61
+ private
62
+
63
+ def rails_production?
64
+ defined?(Rails) && Rails.env.production?
65
+ end
66
+ end
67
+ end
@@ -1,7 +1,5 @@
1
- # typed: ignore
2
1
  # frozen_string_literal: true
3
2
 
4
- require 'schema_dot_org'
5
3
 
6
4
  module SchemaDotOrg
7
5
  # Model the Schema.org `Thing > SearchAction`. See http://schema.org/SearchAction
@@ -1,8 +1,5 @@
1
- # typed: ignore
2
1
  # frozen_string_literal: true
3
2
 
4
- require 'schema_dot_org'
5
- require 'schema_dot_org/search_action'
6
3
 
7
4
  module SchemaDotOrg
8
5
  # Model the Schema.org `Thing > CreativeWork > WebSite`.
@@ -15,9 +12,9 @@ module SchemaDotOrg
15
12
 
16
13
  def _to_json_struct
17
14
  {
18
- 'name' => name,
19
- 'url' => url,
20
- 'potentialAction' => potential_action&.to_json_struct
15
+ 'name' => self.name,
16
+ 'url' => self.url,
17
+ 'potentialAction' => object_to_json_struct(potential_action)
21
18
  }
22
19
  end
23
20
  end
@@ -1,62 +1,25 @@
1
- # typed: ignore
2
1
  # frozen_string_literal: true
3
-
4
- require 'json'
5
- require 'validated_object'
2
+ require 'schema_dot_org/schema_type'
3
+ require 'schema_dot_org/search_action'
4
+ require 'schema_dot_org/web_site'
5
+ require 'schema_dot_org/organization'
6
+ require 'schema_dot_org/product'
7
+ require 'schema_dot_org/item_list'
8
+ require 'schema_dot_org/list_item'
9
+ require 'schema_dot_org/person'
10
+ require 'schema_dot_org/place'
11
+ require 'schema_dot_org/aggregate_offer'
12
+ require 'schema_dot_org/offer'
13
+ require 'schema_dot_org/contact_point'
6
14
 
7
15
  module SchemaDotOrg
8
- #
9
- # Base class for schema types. Refactors out common code.
10
- #
11
- class SchemaType < ValidatedObject::Base
12
- ROOT_ATTR = { '@context' => 'http://schema.org' }.freeze
13
- UNQUALIFIED_CLASS_NAME_REGEX = /([^:]+)$/.freeze
14
-
15
- def to_s
16
- json_string = to_json_ld(pretty: (!rails_production? && !ENV['SCHEMA_DOT_ORG_MINIFIED_JSON']))
17
-
18
- # Mark as safe if we're in Rails
19
- if json_string.respond_to?(:html_safe)
20
- json_string.html_safe
21
- else
22
- json_string
23
- end
24
- end
25
-
26
- def to_json_ld(pretty: false)
27
- "<script type=\"application/ld+json\">\n" + to_json(pretty: pretty, as_root: true) + "\n</script>"
28
- end
29
-
30
- def to_json(pretty: false, as_root: false)
31
- structure = as_root ? ROOT_ATTR.merge(to_json_struct) : to_json_struct
32
-
33
- if pretty
34
- JSON.pretty_generate(structure)
35
- else
36
- structure.to_json
37
- end
38
- end
39
-
40
- # Use the class name to create the "@type" attribute.
41
- # @return a hash structure representing json.
42
- def to_json_struct
43
- { '@type' => un_namespaced_classname }.merge(_to_json_struct.compact)
44
- end
16
+ end
45
17
 
46
- def _to_json_struct
47
- raise 'For subclasses to implement'
48
- end
49
18
 
50
- # @return the classname without the module namespace.
51
- def un_namespaced_classname
52
- self.class.name =~ UNQUALIFIED_CLASS_NAME_REGEX
53
- Regexp.last_match(1)
54
- end
19
+ require 'schema_dot_org/person'
20
+ require 'schema_dot_org/place'
55
21
 
56
- private
22
+ require 'schema_dot_org/organization'
57
23
 
58
- def rails_production?
59
- defined?(Rails) && Rails.env.production?
60
- end
61
- end
62
- end
24
+ require 'schema_dot_org/search_action'
25
+ require 'schema_dot_org/web_site'