class Jekyll::Geolexica::Glossary
Attributes
site[R]
Public Class Methods
new(site)
click to toggle source
# File lib/jekyll/geolexica/glossary.rb, line 14 def initialize(site) @site = site end
Public Instance Methods
language_statistics()
click to toggle source
# File lib/jekyll/geolexica/glossary.rb, line 27 def language_statistics @language_statistics ||= calculate_language_statistics end
load_glossary()
click to toggle source
# File lib/jekyll/geolexica/glossary.rb, line 18 def load_glossary Jekyll.logger.info("Geolexica:", "Loading concepts") Dir.glob(concepts_glob).each { |path| load_concept(path) } end
store(concept)
click to toggle source
Calls superclass method
# File lib/jekyll/geolexica/glossary.rb, line 23 def store(concept) super(concept.data["termid"], concept) end
to_liquid()
click to toggle source
Defines how Glossary
is exposed in Liquid templates.
# File lib/jekyll/geolexica/glossary.rb, line 32 def to_liquid { "language_statistics" => language_statistics, } end
Protected Instance Methods
calculate_language_statistics()
click to toggle source
# File lib/jekyll/geolexica/glossary.rb, line 61 def calculate_language_statistics unsorted = each_value.lazy. flat_map{ |concept| term_languages & concept.data.keys }. group_by(&:itself). transform_values(&:count) # This is not crucial, but gives nicer output, and ensures that # all +term_languages+ are present. term_languages.to_h { |key| [key, unsorted[key] || 0] } end
load_concept(concept_file_path)
click to toggle source
# File lib/jekyll/geolexica/glossary.rb, line 40 def load_concept(concept_file_path) Jekyll.logger.debug("Geolexica:", "reading concept from file #{concept_file_path}") concept_hash = read_concept_file(concept_file_path) preprocess_concept_hash(concept_hash) store Concept.new(concept_hash) rescue Jekyll.logger.error("Geolexica:", "failed to read concept from file #{concept_file_path}") raise end
preprocess_concept_hash(concept_hash)
click to toggle source
Does nothing, but some sites may replace this method.
# File lib/jekyll/geolexica/glossary.rb, line 58 def preprocess_concept_hash(concept_hash) end
read_concept_file(path)
click to toggle source
Reads and parses concept file located at given path.
# File lib/jekyll/geolexica/glossary.rb, line 53 def read_concept_file(path) YAML.load(File.read path) end