Class: UserChoices::LengthConversion

Inherits:
Conversion show all
Defined in:
lib/user-choices/conversions.rb

Overview

:nodoc:

Direct Known Subclasses

ExactLengthConversion, RangeLengthConversion

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Conversion

#convert, #description, for, inherited, is_abstract, record_for

Constructor Details

#initialize(conversion_tag) ⇒ LengthConversion

Returns a new instance of LengthConversion.



111
112
113
114
# File 'lib/user-choices/conversions.rb', line 111

def initialize(conversion_tag)
  super
  @required_length = conversion_tag[:length]
end

Instance Attribute Details

#required_lengthObject (readonly)

Returns the value of attribute required_length.



110
111
112
# File 'lib/user-choices/conversions.rb', line 110

def required_length
  @required_length
end

Class Method Details

.described_by?(conversion_tag, value_class) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/user-choices/conversions.rb', line 116

def self.described_by?(conversion_tag, value_class)
  conversion_tag.is_a?(Hash) && conversion_tag[:length].is_a?(value_class)
end

Instance Method Details

#does_length_check?Boolean

Returns:

  • (Boolean)


124
# File 'lib/user-choices/conversions.rb', line 124

def does_length_check?; true; end

#suitable?(actual) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/user-choices/conversions.rb', line 120

def suitable?(actual)
  actual.respond_to?(:length) && yield
end