Sha256: 58651b9463512734b604ac61c7b1d48db9818fc54f508ec45f60abdad0a61c61

Contents?: true

Size: 537 Bytes

Versions: 15

Compression:

Stored size: 537 Bytes

Contents

require 'devise'
require 'constructor_core/engine'

class String
  def numeric?
    return true if self =~ /^\d+$/
    true if Float(self) rescue false
  end

  def boolean?
    if self =~ (/(true|yes)$/i) || self =~ (/(false|no)$/i)
      return true
    else
      return false
    end
  end

  def to_bool
    return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
    return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
    raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
constructor-core-0.3.3 lib/constructor-core.rb
constructor-core-0.3.2 lib/constructor-core.rb
constructor-core-0.3.1 lib/constructor-core.rb
constructor-core-0.3.0 lib/constructor-core.rb
constructor-core-0.2.14 lib/constructor-core.rb
constructor-core-0.2.12 lib/constructor-core.rb
constructor-core-0.2.11 lib/constructor-core.rb
constructor-core-0.2.10 lib/constructor-core.rb
constructor-core-0.2.9 lib/constructor-core.rb
constructor-core-0.2.8 lib/constructor-core.rb
constructor-core-0.2.6 lib/constructor-core.rb
constructor-core-0.2.5 lib/constructor-core.rb
constructor-core-0.2.4 lib/constructor-core.rb
constructor-core-0.2.1 lib/constructor-core.rb
constructor-cms-0.2.1 core/lib/constructor-core.rb