Sha256: 62fa69b269a3af05f6503654023f68d7a93d4ac521ab74f7764732c69908de3c

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

module GeolexicaServer
  module Generator
    # Class for generating metadata of the glossary
    class Metadata < Base
      def initialize(options)
        super

        @concepts_dir = "#{@glossary_path}/concepts/*.yaml"
        @output_file_name = "metadata.yaml"
      end

      def generate
        terms = extract_terms

        File.open(@output_file_name, "w") do |file|
          file.write(metadata(terms).to_yaml)
        end

        puts "Done."
      end

      private

      def extract_terms
        terms = []

        Dir[@concepts_dir].map do |yaml_file|
          terms << YAML.safe_load(IO.read(yaml_file))
          puts "Processing #{yaml_file}"
        end

        terms
      end

      def metadata(terms)
        {
          "concept_count" => terms.length,
          "term_count" => terms.sum { |t| t.keys.length - 2 },
          "version" => "20220530",
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geolexica-server-0.0.1 lib/geolexica_server/generator/metadata.rb
geolexica-server-0.0.1.pre.beta.pre.32 lib/geolexica_server/generator/metadata.rb