Sha256: 79374dbe040b1fb39d8c61db1283b5ca9045892f6a358dbd7ec65616cf51640a
Contents?: true
Size: 1.25 KB
Versions: 8
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true require "cff" require "dry/monads" require "pathname" module Milestoner module Configuration module Transformers module Citations # Conditionally updates project URI based on citation URL. class URI include Dry::Monads[:result] def initialize key = :project_uri, path: Pathname.pwd.join("CITATION.cff"), citation: CFF::File @key = key @path = path @citation = citation end 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 attr_reader :key, :path, :citation 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 end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems