Sha256: 3c6991dc11300db5f4b019c9658f16f47f7e454486b25ecffca4f5168d38b708

Contents?: true

Size: 817 Bytes

Versions: 24

Compression:

Stored size: 817 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
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
testcentricity_web-3.2.3 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.2 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.2.0 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.11 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.10 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.9.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.9 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.8 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.7 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.6 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.5.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.5 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.4 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.3 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.2 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.1.0 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.20 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.19.1 lib/testcentricity_web/utility_helpers.rb