Sha256: 182e5c5fc61cd08d293db7f7b1866aea9d80661538be79824f40c8165dd64e41

Contents?: true

Size: 1022 Bytes

Versions: 69

Compression:

Stored size: 1022 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 titlecase
    "#{self.split.each{ |text| text.capitalize! }.join(' ')}"
  end

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

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

Version data entries

69 entries across 69 versions & 3 rubygems

Version Path
testcentricity_mobile-4.1.0 lib/testcentricity_mobile/utility_helpers.rb
testcentricity_web-4.6.0 lib/testcentricity_web/utility_helpers.rb
testcentricity_apps-4.0.15 lib/testcentricity_apps/utility_helpers.rb
testcentricity_mobile-4.0.14 lib/testcentricity_mobile/utility_helpers.rb
testcentricity_web-4.5.15 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-4.5.14 lib/testcentricity_web/utility_helpers.rb
testcentricity_apps-4.0.14 lib/testcentricity_apps/utility_helpers.rb
testcentricity_web-4.5.13 lib/testcentricity_web/utility_helpers.rb
testcentricity_mobile-4.0.13 lib/testcentricity_mobile/utility_helpers.rb
testcentricity_apps-4.0.13 lib/testcentricity_apps/utility_helpers.rb
testcentricity_mobile-4.0.12 lib/testcentricity_mobile/utility_helpers.rb
testcentricity_web-4.5.12 lib/testcentricity_web/utility_helpers.rb
testcentricity_apps-4.0.12 lib/testcentricity_apps/utility_helpers.rb
testcentricity_web-4.5.11 lib/testcentricity_web/utility_helpers.rb
testcentricity_mobile-4.0.11 lib/testcentricity_mobile/utility_helpers.rb
testcentricity_web-4.5.10 lib/testcentricity_web/utility_helpers.rb
testcentricity_apps-4.0.11 lib/testcentricity_apps/utility_helpers.rb
testcentricity_mobile-4.0.10 lib/testcentricity_mobile/utility_helpers.rb
testcentricity_web-4.5.9.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_apps-4.0.10 lib/testcentricity_apps/utility_helpers.rb