Sha256: 367b71805e2ae3aedc08ee9e39d775475ea1430cf5431384d12333a98f180870

Contents?: true

Size: 981 Bytes

Versions: 6

Compression:

Stored size: 981 Bytes

Contents

# frozen_string_literal: true

require "cff"
require "dry/monads"
require "pathname"
require "refinements/hash"

module Milestoner
  module Configuration
    module Transformers
      module Citations
        # Conditionally updates project label based on citation details.
        class Label
          include Dry::Monads[:result]

          using Refinements::Hash

          def initialize key = :project_label,
                         path: Pathname.pwd.join("CITATION.cff"),
                         citation: CFF::File
            @key = key
            @path = path
            @citation = citation
          end

          def call content
            content.fetch_value(key) { citation.open(path).title }
                   .then { |value| value unless String(value).empty? }
                   .then { |value| Success content.merge!(key => value) }
          end

          private

          attr_reader :key, :path, :citation
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
milestoner-17.6.0 lib/milestoner/configuration/transformers/citations/label.rb
milestoner-17.5.0 lib/milestoner/configuration/transformers/citations/label.rb
milestoner-17.4.0 lib/milestoner/configuration/transformers/citations/label.rb
milestoner-17.3.0 lib/milestoner/configuration/transformers/citations/label.rb
milestoner-17.2.0 lib/milestoner/configuration/transformers/citations/label.rb
milestoner-17.1.0 lib/milestoner/configuration/transformers/citations/label.rb