Sha256: 984b1f92cfe5ae692797d87004851a893f19b8de9d76d4f3fd73b7525c22da6e

Contents?: true

Size: 770 Bytes

Versions: 1

Compression:

Stored size: 770 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'aequitas/virtus/inline_attribute_rule_extractor/object'

module Aequitas
  module Virtus
    class InlineAttributeRuleExtractor
      class String < Object

        def extract_length_rules
          length = attribute.options.fetch(:length)

          case length
          when Integer; Rule::Length::Equal.new(attribute.name, :expected => length)
          when Range;   Rule::Length::Range.new(attribute.name, :range    => length)
          end
        end

        def extract_format_rules
          format = attribute.options.fetch(:format)
          Rule::Format.new(attribute.name, :with => format)
        end

      end # class String
    end # class InlineAttributeRuleExtractor
  end # module Virtus
end # module Aequitas

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aequitas-0.0.1 lib/aequitas/virtus/inline_attribute_rule_extractor/string.rb