Module: JSON::LD::Utils
- Included in:
- Compact, EvaluationContext, Expand, Flatten, Frame, FromTriples, Triples, Writer
- Defined in:
- lib/json/ld/utils.rb
Instance Method Summary collapse
-
#blank_node?(value) ⇒ Boolean
Is value a blank node? Value is a blank node.
-
#list?(value) ⇒ Boolean
Is value an expaned @list?.
-
#node?(value) ⇒ Boolean
Is value a node? A value is a node if * it is a Hash * it is not a @value, @set or @list * it has more than 1 key or any key is not @id.
-
#node_reference?(value) ⇒ Boolean
Is value a node reference?.
-
#value?(value) ⇒ Boolean
Is value literal?.
Instance Method Details
#blank_node?(value) ⇒ Boolean
Is value a blank node? Value is a blank node
29 30 31 |
# File 'lib/json/ld/utils.rb', line 29 def blank_node?(value) (node?(value) || node_reference?(value)) && value.fetch('@id', '_:')[0,2] == '_:' end |
#list?(value) ⇒ Boolean
Is value an expaned @list?
38 39 40 |
# File 'lib/json/ld/utils.rb', line 38 def list?(value) value.is_a?(Hash) && value.keys == %w(@list) end |
#node?(value) ⇒ Boolean
Is value a node? A value is a node if
-
it is a Hash
-
it is not a @value, @set or @list
-
it has more than 1 key or any key is not @id
10 11 12 13 14 |
# File 'lib/json/ld/utils.rb', line 10 def node?(value) value.is_a?(Hash) && (value.keys & %w(@value @list @set)).empty? && !(value.keys - ['@id']).empty? end |
#node_reference?(value) ⇒ Boolean
Is value a node reference?
20 21 22 |
# File 'lib/json/ld/utils.rb', line 20 def node_reference?(value) value.is_a?(Hash) && value.keys == %w(@id) end |
#value?(value) ⇒ Boolean
Is value literal?
47 48 49 |
# File 'lib/json/ld/utils.rb', line 47 def value?(value) value.is_a?(Hash) && value.has_key?('@value') end |