Sha256: b03cb54288c53200b2d9baf9f7952c3116d9f6baf8d87aea985b5290eb3099c5

Contents?: true

Size: 937 Bytes

Versions: 21

Compression:

Stored size: 937 Bytes

Contents

class Object
  def blank?
    respond_to?(:empty?) ? empty? : !self
  end

  def present?
    !blank?
  end

  def boolean?
    [true, false].include? self
  end
end


class String
  def to_bool
    return true if self == true || self =~ (/(true|t|yes|y|x|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

  def string_between(marker1, marker2)
    self[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
  end

  def format_date_time(date_time_format)
    return if self.blank?
    new_date = DateTime.parse(self)
    if ENV['LOCALE'] && date_time_format.is_a?(Symbol)
      I18n.l(new_date, format: date_time_format)
    else
      new_date.strftime(date_time_format)
    end
  end

  def is_int?
    Integer(self) && true rescue false
  end

  def is_float?
    Float(self) && true rescue false
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
testcentricity_web-3.2.24 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.23 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.22 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.21 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.20 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.19 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.18 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.17 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.16 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.15 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.14 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.13 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.12 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.11 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.10 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.9 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.8 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.7 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.6 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.5 lib/testcentricity_web/utility_helpers.rb