class Jekyll::Geolexica::ConceptSerializer
A decorator responsible for serializing concepts in the most simplistic machine-readable formats like JSON or YAML but unlike RDF ontologies.
Constants
- NON_LANGUAGE_KEYS
Attributes
site[R]
A Jekyll::Site instance.
Public Class Methods
new(concept, site)
click to toggle source
Calls superclass method
# File lib/jekyll/geolexica/concept_serializer.rb, line 16 def initialize(concept, site) super(concept) @site = site end
Public Instance Methods
to_json()
click to toggle source
# File lib/jekyll/geolexica/concept_serializer.rb, line 21 def to_json JSON.dump(in_all_languages) end
to_yaml()
click to toggle source
# File lib/jekyll/geolexica/concept_serializer.rb, line 25 def to_yaml YAML.dump(in_all_languages) end
Private Instance Methods
in_all_languages(concept_hash = data)
click to toggle source
Returns concept hash in all supported languages, with nil
value for every supported language that this concept is not translated to.
# File lib/jekyll/geolexica/concept_serializer.rb, line 33 def in_all_languages(concept_hash = data) hash_keys = NON_LANGUAGE_KEYS + term_languages slice_hash_with_default(concept_hash, nil, *hash_keys) end
slice_hash_with_default(hash, default_value, *keys)
click to toggle source
Like Hash#slice, but takes a default_value
, which is used for every key not present in the hash
.
# File lib/jekyll/geolexica/concept_serializer.rb, line 40 def slice_hash_with_default(hash, default_value, *keys) h = hash.dup keys.each { |k| h[k] ||= default_value } h.slice(*keys) end