class Milestoner::Configuration::Transformers::Citations::URI

Conditionally updates project URI based on citation URL.

Attributes

citation[R]
key[R]
path[R]

Public Class Methods

new(key = :project_uri, path: Pathname.pwd.join("CITATION.cff"), citation: CFF::File) click to toggle source
# File lib/milestoner/configuration/transformers/citations/uri.rb, line 15
def initialize key = :project_uri,
               path: Pathname.pwd.join("CITATION.cff"),
               citation: CFF::File
  @key = key
  @path = path
  @citation = citation
end

Public Instance Methods

call(attributes) click to toggle source
# File lib/milestoner/configuration/transformers/citations/uri.rb, line 23
def call attributes
  process attributes
  Success attributes
rescue KeyError => error
  Failure step: :transform,
          payload: "Unable to transform #{key.inspect}, missing specifier: " \
                   "\"#{error.message[/<.+>/]}\"."
end

Private Instance Methods

process(attributes) click to toggle source
# File lib/milestoner/configuration/transformers/citations/uri.rb, line 36
def process attributes
  attributes.fetch(key) { citation.open(path).url }
            .then { |value| value.match?(/%<.+>s/) ? format(value, attributes) : value }
            .then { |value| attributes.merge! key => value unless value.empty? }
end