<commit_before>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, params.author, params.source, params.subject,
                  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 ||= begin
      hash = Params.members.map { |name| [name, get_param(name)] }.to_h
      Params.new hash[:text], hash[:author], hash[:subject], hash[:source]
    end
  end
end end<commit_msg>SigFromStream#params: simplify Params creation<commit_after>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, params.author, params.source, params.subject,
                  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 ||= begin
      hash = Params.members.map { |name| [name, get_param(name)] }.to_h
      Params.new(*hash.values_at(*Params.members))
    end
  end
end end
{'fraction_non_alphanumeric': 0.1128579449747333, 'fraction_numerical': 0.0, 'mean_word_length': 2.96, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4307832', 'n_tokens_mistral': 600, 'n_tokens_neox': 576, 'n_words': 162}