Sha256: 644f59523cfb68a0e0b9f96650610ecf017de717acf99b2773e17ad45e392f94

Contents?: true

Size: 849 Bytes

Versions: 4

Compression:

Stored size: 849 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(author: params.author, source: params.source,
                    subject: params.subject, tags: tags.required,
                    text: params.text)
    end

    private_attr_reader :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

4 entries across 4 versions & 1 rubygems

Version Path
signore-0.4.2 lib/signore/sig_from_stream.rb
signore-0.4.1 lib/signore/sig_from_stream.rb
signore-0.4.0 lib/signore/sig_from_stream.rb
signore-0.3.3 lib/signore/sig_from_stream.rb