arosa 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 810cb0bb6cbdd8aa9d5a2a465d99275e4830189fd432110f73984c4840bb3b6c
4
+ data.tar.gz: 8c3bd9ece1d575d04151c7d383c000d757050f1784d513335ff0fdc568c2ebe1
5
+ SHA512:
6
+ metadata.gz: 24b4b2ef43dfdc9d01f79bf2d7119998f22372a3e80ce9aa9c348f1346db12916f231dcb2657c6266dc5a985db6a132440818d70bffc68e455c87540c71084a5
7
+ data.tar.gz: 9fcb61eb463aab857ad40b6123447ef3cd5908f76266546fa9dcc62123b3b266abfb4801b15a5f5af2dfa5dc2a6d4626f06b64f6013a5ead8128955b11650586
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Samuenti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # Arosa
2
+
3
+ Generate [schema.org](https://schema.org) structured data as JSON-LD. Drop it into your pages and let search engines understand your content.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'arosa'
9
+ ```
10
+
11
+ Then `bundle install`.
12
+
13
+ ## Usage
14
+
15
+ Arosa works anywhere in your Ruby code. Build the schema, then output it in your view.
16
+
17
+ Here's an example of an Organization schema:
18
+
19
+ ```ruby
20
+ @org = Arosa::Schemas::Organization.new(
21
+ name: "Acme Corp",
22
+ url: "https://acme.com",
23
+ logo: "https://acme.com/logo.png",
24
+ email: "hello@acme.com",
25
+ founding_date: Date.new(2020, 1, 1),
26
+ address: Arosa::Schemas::PostalAddress.new(
27
+ street_address: "123 Main St",
28
+ address_locality: "Zug",
29
+ address_country: "CH",
30
+ postal_code: "6300"
31
+ )
32
+ )
33
+ ```
34
+
35
+ In your view:
36
+
37
+ ```erb
38
+ <%= @org %>
39
+ ```
40
+
41
+ Which will output:
42
+
43
+ ```html
44
+ <script type="application/ld+json">
45
+ {
46
+ "@context": "https://schema.org",
47
+ "@type": "Organization",
48
+ "name": "Acme Corp",
49
+ "url": "https://acme.com",
50
+ "logo": "https://acme.com/logo.png",
51
+ "email": "hello@acme.com",
52
+ "foundingDate": "2020-01-01",
53
+ "address": {
54
+ "@type": "PostalAddress",
55
+ "streetAddress": "123 Main St",
56
+ "addressLocality": "Zug",
57
+ "addressCountry": "CH",
58
+ "postalCode": "6300"
59
+ }
60
+ }
61
+ </script>
62
+ ```
63
+
64
+ ## Validation
65
+
66
+ Wrong types and unknown properties raise errors immediately:
67
+
68
+ ```ruby
69
+ Arosa::Schemas::Organization.new(name: 123)
70
+ # => ArgumentError: name must be a String, got Integer
71
+
72
+ Arosa::Schemas::Organization.new(made_up: "value")
73
+ # => NoMethodError: undefined method `made_up='
74
+ ```
75
+
76
+ No silent failures. If it builds, the markup is valid.
77
+
78
+ ## Supported Types
79
+
80
+ | Type | Schema.org |
81
+ |------|------------|
82
+ | [Organization](#organization) | [schema.org/Organization](https://schema.org/Organization) |
83
+ | [PostalAddress](#postaladdress) | [schema.org/PostalAddress](https://schema.org/PostalAddress) |
84
+ | [ContactPoint](#contactpoint) | [schema.org/ContactPoint](https://schema.org/ContactPoint) |
85
+ | [BreadcrumbList](#breadcrumblist) | [schema.org/BreadcrumbList](https://schema.org/BreadcrumbList) |
86
+ | [ListItem](#listitem) | [schema.org/ListItem](https://schema.org/ListItem) |
87
+
88
+ More types coming.
89
+
90
+ ---
91
+
92
+ ### Organization
93
+
94
+ | Property | Type |
95
+ |----------|------|
96
+ | name | String |
97
+ | alternate_name | String |
98
+ | description | String |
99
+ | url | String |
100
+ | logo | String |
101
+ | email | String |
102
+ | telephone | String |
103
+ | address | [PostalAddress](#postaladdress) |
104
+ | contact_point | [ContactPoint](#contactpoint) |
105
+ | legal_name | String |
106
+ | tax_id | String |
107
+ | vat_id | String |
108
+ | duns | String |
109
+ | lei_code | String |
110
+ | iso6523_code | String |
111
+ | global_location_number | String |
112
+ | naics | String |
113
+ | founding_date | Date |
114
+ | number_of_employees | Integer |
115
+ | same_as | Array of String |
116
+
117
+ ```ruby
118
+ Arosa::Schemas::Organization.new(
119
+ name: "Acme Corp",
120
+ url: "https://acme.com",
121
+ logo: "https://acme.com/logo.png",
122
+ email: "hello@acme.com",
123
+ founding_date: Date.new(2020, 1, 1),
124
+ same_as: [
125
+ "https://linkedin.com/company/acme",
126
+ "https://en.wikipedia.org/wiki/Acme"
127
+ ],
128
+ address: Arosa::Schemas::PostalAddress.new(
129
+ street_address: "123 Main St",
130
+ address_locality: "Zug",
131
+ address_country: "CH",
132
+ postal_code: "6300"
133
+ ),
134
+ contact_point: Arosa::Schemas::ContactPoint.new(
135
+ contact_type: "customer service",
136
+ telephone: "+1-800-555-1234",
137
+ email: "support@acme.com"
138
+ )
139
+ )
140
+ ```
141
+
142
+ ### PostalAddress
143
+
144
+ | Property | Type |
145
+ |----------|------|
146
+ | street_address | String |
147
+ | address_locality | String |
148
+ | address_region | String |
149
+ | postal_code | String |
150
+ | address_country | String |
151
+
152
+ ```ruby
153
+ Arosa::Schemas::PostalAddress.new(
154
+ street_address: "123 Main St",
155
+ address_locality: "Zug",
156
+ address_region: "ZG",
157
+ address_country: "CH",
158
+ postal_code: "6300"
159
+ )
160
+ ```
161
+
162
+ ### ContactPoint
163
+
164
+ | Property | Type |
165
+ |----------|------|
166
+ | contact_type | String |
167
+ | telephone | String |
168
+ | email | String |
169
+
170
+ ```ruby
171
+ Arosa::Schemas::ContactPoint.new(
172
+ contact_type: "customer service",
173
+ telephone: "+1-800-555-1234",
174
+ email: "support@example.com"
175
+ )
176
+ ```
177
+
178
+ ### BreadcrumbList
179
+
180
+ | Property | Type |
181
+ |----------|------|
182
+ | item_list_element | Array of [ListItem](#listitem) |
183
+
184
+ ```ruby
185
+ Arosa::Schemas::BreadcrumbList.new(
186
+ item_list_element: [
187
+ Arosa::Schemas::ListItem.new(position: 1, name: "Home", item: "https://example.com"),
188
+ Arosa::Schemas::ListItem.new(position: 2, name: "Books", item: "https://example.com/books"),
189
+ Arosa::Schemas::ListItem.new(position: 3, name: "Science Fiction")
190
+ ]
191
+ )
192
+ ```
193
+
194
+ ### ListItem
195
+
196
+ | Property | Type |
197
+ |----------|------|
198
+ | position | Integer |
199
+ | name | String |
200
+ | item | String |
201
+
202
+ ```ruby
203
+ Arosa::Schemas::ListItem.new(
204
+ position: 1,
205
+ name: "Books",
206
+ item: "https://example.com/books"
207
+ )
208
+ ```
209
+
210
+ Note: `item` is optional on the last breadcrumb (the current page).
211
+
212
+ ## License
213
+
214
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ class Schema
5
+ class << self
6
+ def properties
7
+ @properties ||= {}
8
+ end
9
+
10
+ def property(name, required: false, type: nil)
11
+ properties[name] = { required: required, type: type }
12
+
13
+ define_method(name) do
14
+ @values[name]
15
+ end
16
+
17
+ define_method("#{name}=") do |value|
18
+ validate_type!(name, value, type) if type && !value.nil?
19
+ @values[name] = value
20
+ end
21
+ end
22
+
23
+ def schema_type(type = nil)
24
+ if type
25
+ @schema_type = type
26
+ else
27
+ @schema_type || name.split("::").last
28
+ end
29
+ end
30
+
31
+ def inherited(subclass)
32
+ super
33
+ subclass.instance_variable_set(:@properties, properties.dup)
34
+ end
35
+ end
36
+
37
+ def initialize(**attrs)
38
+ @values = {}
39
+ attrs.each { |key, value| send("#{key}=", value) }
40
+ raise ArgumentError, "Missing required: #{missing_required.join(", ")}" if missing_required.any?
41
+ end
42
+
43
+ def valid?
44
+ missing_required.empty?
45
+ end
46
+
47
+ def missing_required
48
+ self.class.properties.select { |_, opts| opts[:required] }.keys.reject { |name| @values[name] }
49
+ end
50
+
51
+ def to_h(nested: false)
52
+ data = nested ? {} : { "@context" => "https://schema.org" }
53
+ data["@type"] = self.class.schema_type
54
+
55
+ @values.each do |key, value|
56
+ data[camelize(key)] = serialize_value(value)
57
+ end
58
+
59
+ data.compact
60
+ end
61
+
62
+ def to_json(*_args)
63
+ JSON.generate(to_h)
64
+ end
65
+
66
+ def to_html
67
+ html = %(<script type="application/ld+json">#{to_json}</script>)
68
+ html.respond_to?(:html_safe) ? html.html_safe : html
69
+ end
70
+
71
+ alias to_s to_html
72
+
73
+ private
74
+
75
+ def validate_type!(name, value, type)
76
+ if type.is_a?(Array)
77
+ inner = type.first
78
+ return if value.is_a?(inner)
79
+ return if value.is_a?(Array) && value.all? { |v| v.is_a?(inner) }
80
+ else
81
+ return if value.is_a?(type)
82
+ end
83
+
84
+ raise ArgumentError, "#{name} must be a #{type}, got #{value.class}"
85
+ end
86
+
87
+ def camelize(key)
88
+ str = key.to_s
89
+ str.gsub(/_([a-z])/) { ::Regexp.last_match(1).upcase }
90
+ end
91
+
92
+ def serialize_value(value)
93
+ case value
94
+ when Schema then value.to_h(nested: true)
95
+ when Array then value.map { |v| serialize_value(v) }
96
+ when Date, Time, DateTime then value.iso8601
97
+ else value
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ module Schemas
5
+ # Schema.org BreadcrumbList type
6
+ #
7
+ # https://schema.org/BreadcrumbList
8
+ class BreadcrumbList < Schema
9
+ schema_type "BreadcrumbList"
10
+
11
+ property :item_list_element, type: [ListItem]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ module Schemas
5
+ # Schema.org ContactPoint type
6
+ #
7
+ # https://schema.org/ContactPoint
8
+ class ContactPoint < Schema
9
+ schema_type "ContactPoint"
10
+
11
+ property :contact_type, type: String
12
+ property :telephone, type: String
13
+ property :email, type: String
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ module Schemas
5
+ # Schema.org ListItem type
6
+ #
7
+ # https://schema.org/ListItem
8
+ class ListItem < Schema
9
+ schema_type "ListItem"
10
+
11
+ property :position, type: Integer
12
+ property :name, type: String
13
+ property :item, type: String
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ module Schemas
5
+ # Schema.org Organization type
6
+ #
7
+ # https://schema.org/Organization
8
+ class Organization < Schema
9
+ schema_type "Organization"
10
+
11
+ property :name, type: String
12
+ property :alternate_name, type: String
13
+ property :description, type: String
14
+ property :url, type: String
15
+ property :logo, type: String
16
+ property :email, type: String
17
+ property :telephone, type: String
18
+ property :address, type: PostalAddress
19
+ property :contact_point, type: ContactPoint
20
+ property :legal_name, type: String
21
+ property :tax_id, type: String
22
+ property :vat_id, type: String
23
+ property :duns, type: String
24
+ property :lei_code, type: String
25
+ property :iso6523_code, type: String
26
+ property :global_location_number, type: String
27
+ property :naics, type: String
28
+ property :founding_date, type: Date
29
+ property :number_of_employees
30
+ property :same_as, type: [String]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ module Schemas
5
+ # Schema.org PostalAddress type
6
+ #
7
+ # https://schema.org/PostalAddress
8
+ class PostalAddress < Schema
9
+ schema_type "PostalAddress"
10
+
11
+ property :street_address, type: String
12
+ property :address_locality, type: String
13
+ property :address_region, type: String
14
+ property :postal_code, type: String
15
+ property :address_country, type: String
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arosa
4
+ VERSION = "0.1.0"
5
+ end
data/lib/arosa.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "json"
5
+ require_relative "arosa/version"
6
+ require_relative "arosa/schema"
7
+
8
+ # Schemas
9
+ require_relative "arosa/schemas/postal_address"
10
+ require_relative "arosa/schemas/contact_point"
11
+ require_relative "arosa/schemas/organization"
12
+ require_relative "arosa/schemas/list_item"
13
+ require_relative "arosa/schemas/breadcrumb_list"
14
+
15
+ module Arosa
16
+ class Error < StandardError; end
17
+ end
data/sig/arosa.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Arosa
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arosa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuenti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby gem for generating schema.org structured data for rich results.
14
+ email:
15
+ - contact@samuenti.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - Rakefile
23
+ - lib/arosa.rb
24
+ - lib/arosa/schema.rb
25
+ - lib/arosa/schemas/breadcrumb_list.rb
26
+ - lib/arosa/schemas/contact_point.rb
27
+ - lib/arosa/schemas/list_item.rb
28
+ - lib/arosa/schemas/organization.rb
29
+ - lib/arosa/schemas/postal_address.rb
30
+ - lib/arosa/version.rb
31
+ - sig/arosa.rbs
32
+ homepage: https://github.com/samuenti/arosa
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/samuenti/arosa
37
+ source_code_uri: https://github.com/samuenti/arosa
38
+ rubygems_mfa_required: 'true'
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.4.19
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Generate schema.org structured data as JSON-LD
58
+ test_files: []