Sha256: 7211fa4c9dcb43d870e62779226b3c8c659b4705f6f347fd747a6f54fa65f4e4

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "relaton"

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

        @input_file = "#{@glossary_path}/bibliography.yaml"
        @output_dir = "bibliography"

        @bibliography_map = YAML.load_file(@input_file)
        @db = Relaton::Db.new(nil, nil)
      end

      def generate
        Dir.mkdir(@output_dir) unless File.directory?(@output_dir)

        @bibliography_map.each do |name, identifier|
          bib =
            @db.fetch(identifier["reference"]) ||
            user_defined_bib(identifier)

          file_path = "#{@output_dir}/#{name}.yaml"
          File.write(file_path, bib.to_yaml)
        end
      end

      private

      def user_defined_bib(identifier)
        {
          "user_defined" => true,
          "reference" => identifier["reference"],
          "link" => identifier["link"],
        }.compact
      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/bibliography.rb
geolexica-server-0.0.1.pre.beta.pre.32 lib/geolexica_server/generator/bibliography.rb