11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/hypermicrodata/serializer/jsonld.rb', line 11
def to_hash
hash = {}
hash[:id] = unwrap(id) if id
re_schema_org = %r|^http://schema\.org/|i
if type.all?{|t| t.match(re_schema_org) }
hash['@context'] = 'http://schema.org'
hash['@type'] = unwrap(type.map{|t| t.sub(re_schema_org, '') })
else
hash['@type'] = unwrap(type)
end
properties.each do |name, values|
final_values = values.map do |value|
if value.is_a?(Hypermicrodata::Item)
value.to_hash
else
value
end
end
hash[name] = unwrap(final_values)
end
hash
end
|