izi_json_ld 1.0.7 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ec495cac09672d3ff4561af894fa3af2fba2a8d
4
- data.tar.gz: 20e90d7eded79d6e3a4974bf96d286d09de77389
3
+ metadata.gz: dcc874ab5405c6e7f56fc9bde4bec4e288b44831
4
+ data.tar.gz: a2f871bd7e3a815180c17a2395a1e4744e0a54bf
5
5
  SHA512:
6
- metadata.gz: 782a8cfc927ed88896335c18196069fc420a816f5b71b610a2802bba16d361f0b6fcb3663c30666bb5133a41e32ab61c4ba302db72b3e0224cfcda339cebc7db
7
- data.tar.gz: 5fd3171e82f21a8c04040e99ce25522f8da7431b40302372e8cdcba9e0ac602c282cfa9eab2bd8142c68c4cb65099a7f1082a9b96d850d91f35d3b2b52dc083b
6
+ metadata.gz: d6cc1e6e99a9e7a40d82ee84d0499bd3e39f2743e268e1d403feab724351847e4e3f84fa9b2e7f04a0b00a058604ed811a13042e62674c17bdfbc6a2fa7080f9
7
+ data.tar.gz: 582a5dc61fb74a9db7dd4c61058bf7c0e0e3f5b83ea91de48312c3e27c9c4fa04c76b0c90d2a9d800ba85926922fd123675c4980ef0d7e8b91f7188667d6c757
@@ -5,10 +5,16 @@ class PersonEntity < ApplicationEntity
5
5
  attribute :person_name, ::IziJsonLd::Types::String
6
6
  attribute? :email, ::IziJsonLd::Types::String.optional
7
7
  attribute? :image, ::IziJsonLd::Types::String.optional
8
- attribute? :sameAs, ::IziJsonLd::Types::String.optional
8
+ attribute? :sameAs, ::IziJsonLd::Types::OneOrMore[::IziJsonLd::Types::String].optional
9
9
  attribute? :worksFor, ::OrganizationEntity
10
+ attribute? :url, ::IziJsonLd::Types::String.optional
11
+ attribute? :jobTitle, ::IziJsonLd::Types::String.optional
10
12
 
11
13
  def dump_attributes
12
14
  attributes.except(:person_name).merge(name: person_name)
13
15
  end
16
+
17
+ def name
18
+ person_name
19
+ end
14
20
  end
@@ -4,11 +4,29 @@ class ProductEntity < ApplicationEntity
4
4
  type 'Product'
5
5
 
6
6
  attribute :name, ::IziJsonLd::Types::String
7
- attribute? :brand, ::IziJsonLd::Types::String.optional
7
+ attribute? :brand, (::IziJsonLd::Types::Strict::String | ::OrganizationEntity).optional
8
8
  attribute? :image, ::IziJsonLd::Types::String.optional
9
9
  attribute? :description, ::IziJsonLd::Types::String.optional
10
+ attribute? :sku, ::IziJsonLd::Types::String.optional
11
+ attribute? :gtin, ::IziJsonLd::Types::String.optional
12
+ attribute? :mpn, ::IziJsonLd::Types::String.optional
10
13
 
11
14
  attribute? :offers, OfferEntity.optional
12
15
  attribute? :aggregateRating, AggregateRatingEntity.optional
13
16
  attribute? :review, ::IziJsonLd::Types::OneOrMore[::ReviewEntity].optional
17
+
18
+ def dump_attributes
19
+ attributes.except(:brand).merge(
20
+ brand: safe_brand
21
+ )
22
+ end
23
+
24
+ private
25
+
26
+ def safe_brand
27
+ return if brand.blank?
28
+ return brand unless brand.is_a?(String)
29
+
30
+ ::OrganizationEntity.new(name: brand)
31
+ end
14
32
  end
@@ -3,9 +3,33 @@
3
3
  class ReviewEntity < ApplicationEntity
4
4
  type 'Review'
5
5
 
6
- attribute? :author, ::IziJsonLd::Types::String.optional
6
+ attribute? :author, (::IziJsonLd::Types::Strict::String | ::PersonEntity | ::OrganizationEntity).optional
7
+ attribute? :publisher, (::IziJsonLd::Types::Strict::String | ::PersonEntity | ::OrganizationEntity).optional
7
8
  attribute? :reviewRating, RatingEntity.optional
8
9
  attribute? :reviewBody, ::IziJsonLd::Types::String.optional
9
10
 
10
11
  attribute? :datePublished, ::IziJsonLd::Types::DateTime.optional
12
+
13
+ def dump_attributes
14
+ attributes.except(:author, :publisher).merge(
15
+ author: safe_author,
16
+ publisher: safe_publisher
17
+ )
18
+ end
19
+
20
+ private
21
+
22
+ def safe_author
23
+ return if author.blank?
24
+ return author unless author.is_a?(String)
25
+
26
+ ::PersonEntity.new(person_name: author)
27
+ end
28
+
29
+ def safe_publisher
30
+ return if publisher.blank?
31
+ return publisher unless publisher.is_a?(String)
32
+
33
+ ::OrganizationEntity.new(name: publisher)
34
+ end
11
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziJsonLd
4
- VERSION = '1.0.7'
4
+ VERSION = '1.0.11'
5
5
  end