0.0
The project is in a healthy, maintained state
Generated schema.org type descriptors with checked properties and JSON-LD serialization.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 2.7
 Project Readme

schema_org-rb

Gem Version Release

schema_org-rb provides generated Ruby descriptors for the Schema.org vocabulary. The checked-in vocabulary version is exposed as SchemaOrg::SCHEMA_VERSION.

Installation

gem "schema_org-rb", "0.2.0"

Supported Ruby versions

The gem supports Ruby 3.2, 3.3, 3.4, and 4.0.

Usage

Construct generated types with snake_case properties. Values are checked on construction and mutation.

Schema.org type names generally map directly to Ruby constants. The exception in the current vocabulary is 3DModel, which is exposed as SchemaOrg::ThreeDModel because Ruby constants cannot begin with a digit.

require "schema_org"
require "date"

person = SchemaOrg::Person.new(
  name: "Jane Doe",
  job_title: "Professor",
  birth_date: Date.new(1980, 1, 2),
  address: SchemaOrg::PostalAddress.new(address_locality: "Seattle"),
  colleague: ["https://example.test/alice", "https://example.test/bob"]
)
person.job_title = "Researcher"
person.birth_date = nil

person.schema_type?(SchemaOrg::Thing) # true
person.as_jsonld
# => {
#      "@context" => "https://schema.org",
#      "@type" => "Person",
#      "address" => {
#        "@type" => "PostalAddress",
#        "addressLocality" => "Seattle"
#      },
#      "colleague" => [
#        "https://example.test/alice",
#        "https://example.test/bob"
#      ],
#      "jobTitle" => "Researcher",
#      "name" => "Jane Doe"
#    }
person.to_json

Nested enumeration values are constants:

offer = SchemaOrg::Offer.new(availability: SchemaOrg::ItemAvailability::IN_STOCK)
offer.to_json # includes https://schema.org/InStock

as_jsonld returns string-keyed JSON-LD. Only the root object includes @context; nested schema values are serialized recursively. Arrays, native Date, DateTime, and Time values are supported.

RBS support

The gem ships generated RBS signatures covering the complete checked-in Schema.org vocabulary. Type checkers such as RBS and Steep can use these signatures for static checking and editor features.

If the signature is too large for your type-checking setup, configure RBS Collection to ignore it:

# rbs_collection.yaml
gems:
  - name: schema_org-rb
    ignore: true

Licensing and attribution

Project-authored material and generator-emitted Ruby/RBS structure are offered under MIT. The complete codegen/data/schema.ttl snapshot and Schema.org descriptions copied from it into generated type/property comments and comment_lines metadata remain CC BY-SA 3.0. See LICENSE.txt and LICENSE-SCHEMA-ORG.txt, and the Schema.org terms.

The CC BY-SA Turtle snapshot is maintainer input tracked in this repository and is not included in the gem. The source release is the one exposed by SchemaOrg::SCHEMA_VERSION at https://schema.org/version/<version without leading v>/schemaorg-all-https.ttl.

Contributing

See the repository's CONTRIBUTING.md for Schema.org update and release procedures.