<commit_before>require "vulcanize/version"

module Vulcanize
  class Form
    def self.attributes
      @attributes ||= {}
    end


    def self.attribute(attribute_name, type, required: false, default: nil, from: nil)
      attributes[attribute_name] = true
      # from = from || attribute_name
      define_method attribute_name do |&block|
        begin
          raw = input[attribute_name]
          # raw = self.input.fetch(from) { '' }
          # raise MissingAttribute if required && raw.empty?
          return type.new raw
        rescue ArgumentError => err
          return block.call raw, err if block
          raise
        end
      end
      tmp_attributes = attributes

      define_method :attributes do
        tmp_attributes
      end
    end
    include Enumerable
    # http://blog.arkency.com/2014/01/ruby-to-enum-for-enumerator/
    def each
      attributes.each do |attribute, value|
        yield attribute, public_send(attribute)
      end
    end

    def initialize(input={})
      @input = input
    end

    def valid?
      attributes.keys.each(&method(:send))
      true
    rescue
      false
    end

    attr_reader :input

  end
end<commit_msg>upgrade comments<commit_after>require "vulcanize/version"

module Vulcanize
  # module Checkbox
  #   def new(raw)
  #     return true if raw == 'on'
  #     raise ArgumentError
  #   end
  # end
  class Form
    def self.attributes
      @attributes ||= {}
    end

    def self.attribute(attribute_name, type, required: false, default: nil, from: nil, private: false)
      # attribute_name = attribute_name.to_sym
      attributes[attribute_name] = true
      # from = from.to_sym || attribute_name
      define_method attribute_name do |&block|
        begin
          raw = input[attribute_name]
          # raw = self.input.fetch(from) { '' }
          # raise MissingAttribute if required && raw.empty?
          # return default if raw.empty?
          return type.new raw
        rescue ArgumentError => err
          return block.call raw, err if block
          raise
        end
      end
      tmp_attributes = attributes
      # private attribute_name if private

      define_method :attributes do
        tmp_attributes
      end
    end
    include Enumerable
    # http://blog.arkency.com/2014/01/ruby-to-enum-for-enumerator/
    def each
      attributes.each do |attribute, value|
        yield attribute, public_send(attribute)
      end
    end

    def initialize(input={})
      # handle symbolize keys
      @input = input
    end

    def valid?
      attributes.keys.each(&method(:send))
      true
      # handle argument error an missing error.
    rescue
      false
    end

    attr_reader :input

  end
end
{'fraction_non_alphanumeric': 0.07963302752293577, 'fraction_numerical': 0.004403669724770643, 'mean_word_length': 2.1118721461187215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6152758', 'n_tokens_mistral': 785, 'n_tokens_neox': 758, 'n_words': 216}