Sha256: 9c4d4a0278e1ba1e11b3e925e17e4310885293ee2f157754c6196d7d32b4a628

Contents?: true

Size: 858 Bytes

Versions: 2

Compression:

Stored size: 858 Bytes

Contents

require_relative 'signature'
require_relative 'tags'

module Signore
  class SigFromStream
    Params = Struct.new(*%i(text author subject source))

    def self.sig_from(input, tags: Tags.new)
      new(input, tags: tags).to_sig
    end

    def initialize(input, tags: Tags.new)
      @input = input
      @tags  = tags
    end

    def to_sig
      Signature.new(params.text, author: params.author, source: params.source,
                                 subject: params.subject, tags: tags.required)
    end

    attr_reader :input, :tags
    private     :input, :tags

    private

    def get_param(param)
      puts "#{param}?"
      ''.tap do |value|
        value << input.gets until value.lines.to_a.last == "\n"
      end.strip
    end

    def params
      @params ||= Params.new(*Params.members.map { |name| get_param(name) })
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
signore-0.2.4 lib/signore/sig_from_stream.rb
signore-0.2.3 lib/signore/sig_from_stream.rb