Class: UserChoices::ConversionToInteger

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

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Conversion

#does_length_check?, for, inherited, #initialize, is_abstract, record_for

Constructor Details

This class inherits a constructor from UserChoices::Conversion

Class Method Details

.described_by?(conversion_tag) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/user-choices/conversions.rb', line 52

def self.described_by?(conversion_tag)
  conversion_tag == :integer
end

Instance Method Details

#convert(value) ⇒ Object



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

def convert(value); value.to_i; end

#descriptionObject



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

def description; "an integer"; end

#suitable?(actual) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/user-choices/conversions.rb', line 58

def suitable?(actual)
 return true if actual.is_a?(Integer)
 actual.is_a?(String) and /^\d+$/ =~ actual # String check for better error message.
end