Class: UserChoices::ConversionToBoolean

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)


67
68
69
# File 'lib/user-choices/conversions.rb', line 67

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

Instance Method Details

#convert(value) ⇒ Object



79
80
81
82
83
84
# File 'lib/user-choices/conversions.rb', line 79

def convert(value)
  case value
  when String then eval(value.downcase)
  else value
  end
end

#descriptionObject



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

def description; "a boolean"; end

#suitable?(actual) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/user-choices/conversions.rb', line 73

def suitable?(actual)
  return true if [true, false].include?(actual)
  return false unless actual.is_a?(String)
  ['true', 'false'].include?(actual.downcase)
end