emp_json 1.4.0 → 1.5.0.pre.g5eec38832
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/empathy/emp_json/helpers/primitives.rb +13 -3
- data/lib/empathy/emp_json/helpers/slices.rb +8 -4
- data/lib/empathy/emp_json/serializer/fields.rb +1 -1
- data/lib/empathy/emp_json/version.rb +1 -1
- data/sig/lib/empathy/emp_json/helpers/primitives.rbs +8 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42a7ee8f987922575b898af0f2166deb5f06645a8bb6dd7af1844384883f1de1
|
4
|
+
data.tar.gz: 00e02e32f02ea629ef7d70156d2d2e911ee4e67133ee6f3a9d65e00e46711eda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64db6485db89cac819e8bdbc31f01e925b301a23286de9df69d5335cc477c5812aae187785bc562d39c18933b911ee8886b926f83abacc85bd0845335f5d4896
|
7
|
+
data.tar.gz: d31b26826e6966a7162892f99153be3cdaaa1baf1aac5e699232487294c1d04f1b415f4a6088fd0a4bf07776ee34aea17f9d7cfbf1604b75018736fd556dcdf2
|
data/Gemfile.lock
CHANGED
@@ -14,6 +14,7 @@ module Empathy
|
|
14
14
|
EMP_TYPE_STRING = "s"
|
15
15
|
EMP_TYPE_BOOL = "b"
|
16
16
|
EMP_TYPE_INTEGER = "i"
|
17
|
+
EMP_TYPE_DOUBLE = "d"
|
17
18
|
EMP_TYPE_LONG = "l"
|
18
19
|
EMP_TYPE_PRIMITIVE = "p"
|
19
20
|
EMP_TYPE_LANGSTRING = "ls"
|
@@ -28,6 +29,9 @@ module Empathy
|
|
28
29
|
RDF_XSD_DATETIME = "#{RDF_XSD}dateTime"
|
29
30
|
RDF_XSD_BOOLEAN = "#{RDF_XSD}boolean"
|
30
31
|
RDF_XSD_INTEGER = "#{RDF_XSD}integer"
|
32
|
+
RDF_XSD_FLOAT = "#{RDF_XSD}float"
|
33
|
+
RDF_XSD_DOUBLE = "#{RDF_XSD}double"
|
34
|
+
RDF_XSD_DECIMAL = "#{RDF_XSD}decimal"
|
31
35
|
|
32
36
|
def object_to_value(value)
|
33
37
|
return primitive_to_value(value.iri) if value.respond_to?(:iri)
|
@@ -59,7 +63,9 @@ module Empathy
|
|
59
63
|
shorthand(EMP_TYPE_BOOL, value.to_s)
|
60
64
|
when Integer
|
61
65
|
integer_to_value(value)
|
62
|
-
when Float
|
66
|
+
when Float
|
67
|
+
shorthand(EMP_TYPE_DOUBLE, value.to_s)
|
68
|
+
when Numeric
|
63
69
|
use_rdf_rb_for_primitive(value)
|
64
70
|
when RDF::Literal
|
65
71
|
rdf_literal_to_value(value)
|
@@ -79,7 +85,7 @@ module Empathy
|
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
82
|
-
def rdf_literal_to_value(value) # rubocop:disable Metrics/AbcSize
|
88
|
+
def rdf_literal_to_value(value) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
83
89
|
case value.datatype.to_s
|
84
90
|
when RDF_RDFV_LANGSTRING
|
85
91
|
{
|
@@ -95,10 +101,14 @@ module Empathy
|
|
95
101
|
shorthand(EMP_TYPE_DATETIME, value.value)
|
96
102
|
when RDF_XSD_BOOLEAN
|
97
103
|
shorthand(EMP_TYPE_BOOL, value.value)
|
104
|
+
when RDF_XSD_DOUBLE
|
105
|
+
shorthand(EMP_TYPE_DOUBLE, value.value)
|
106
|
+
when RDF_XSD_DECIMAL, RDF_XSD_FLOAT
|
107
|
+
primitive(value.datatype.to_s, value.value)
|
98
108
|
when RDF_XSD_INTEGER
|
99
109
|
integer_to_value(value.to_i)
|
100
110
|
else
|
101
|
-
throw "unknown RDF::Literal"
|
111
|
+
throw "unknown RDF::Literal: #{value.datatype}"
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
@@ -46,7 +46,7 @@ module Empathy
|
|
46
46
|
|
47
47
|
# Returns a record from a slice.
|
48
48
|
def record_from_slice(slice, id, website_iri = nil)
|
49
|
-
slice[absolutized_id(
|
49
|
+
slice[absolutized_id(retrieve_id_string(id), website_iri)] || slice[retrieve_id_string(id)]
|
50
50
|
end
|
51
51
|
|
52
52
|
def field_from_record(record, field)
|
@@ -56,15 +56,19 @@ module Empathy
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def retrieve_id(resource)
|
59
|
-
return resource
|
59
|
+
return resource if resource.is_a?(URI) || resource.is_a?(RDF::URI) || resource.is_a?(RDF::Node)
|
60
60
|
|
61
61
|
resource.try(:iri) || resource.try(:subject) || resource.try(:id) || resource
|
62
62
|
end
|
63
63
|
|
64
|
+
def retrieve_id_string(resource)
|
65
|
+
retrieve_id(resource).to_s
|
66
|
+
end
|
67
|
+
|
64
68
|
def absolutized_id(id, website_iri = nil)
|
65
|
-
return id.
|
69
|
+
return id.delete_prefix(website_iri) if website_iri.present?
|
66
70
|
|
67
|
-
id
|
71
|
+
id
|
68
72
|
end
|
69
73
|
|
70
74
|
def normalise_slice_values(values)
|
@@ -58,7 +58,7 @@ module Empathy
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def value_for_attribute(attr, resource, serialization_params)
|
61
|
-
return resource.try(attr.method) if attr.method.is_a?(Symbol)
|
61
|
+
return resource.try(attr.method) if attr.method.is_a?(Symbol) || attr.method.is_a?(String)
|
62
62
|
|
63
63
|
FastJsonapi.call_proc(attr.method, resource, serialization_params)
|
64
64
|
end
|
@@ -16,6 +16,8 @@ module Empathy
|
|
16
16
|
|
17
17
|
EMP_TYPE_INTEGER: "i"
|
18
18
|
|
19
|
+
EMP_TYPE_DOUBLE: "d"
|
20
|
+
|
19
21
|
EMP_TYPE_LONG: "l"
|
20
22
|
|
21
23
|
EMP_TYPE_PRIMITIVE: "p"
|
@@ -42,6 +44,12 @@ module Empathy
|
|
42
44
|
|
43
45
|
RDF_XSD_INTEGER: "http://www.w3.org/2001/XMLSchema#integer"
|
44
46
|
|
47
|
+
RDF_XSD_FLOAT: "http://www.w3.org/2001/XMLSchema#float"
|
48
|
+
|
49
|
+
RDF_XSD_DOUBLE: "http://www.w3.org/2001/XMLSchema#double"
|
50
|
+
|
51
|
+
RDF_XSD_DECIMAL: "http://www.w3.org/2001/XMLSchema#decimal"
|
52
|
+
|
45
53
|
type shorthand = { type: string, v: string }
|
46
54
|
type primitive = { type: string, dt: string, v: string }
|
47
55
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emp_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0.pre.g5eec38832
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom van Kalkeren
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Serializer for the EmpJson specification.
|
14
14
|
email:
|
@@ -75,9 +75,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: 2.7.0.preview1
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 1.3.1
|
81
81
|
requirements: []
|
82
82
|
rubygems_version: 3.3.7
|
83
83
|
signing_key:
|