Sha256: 2332a1ecc87cb1a9cc9b29179d674cfc5aea68cc4c2fee97b47f4ed8a715999b

Contents?: true

Size: 640 Bytes

Versions: 53

Compression:

Stored size: 640 Bytes

Contents

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

  def present?
    !blank?
  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)
    new_date.strftime(date_time_format)
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
testcentricity-2.4.2 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.4.2 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.4.1 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.4.1 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.4.0 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.4.0 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.3.19 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.3.19 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.3.18 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.3.18 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.3.17 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.3.17 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.3.16.1 lib/testcentricity/utility_helpers.rb
testcentricity-2.3.16 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.3.16 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-2.3.15.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-2.3.15 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-2.3.14.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-2.3.14 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.3.14 lib/testcentricity/utility_helpers.rb