Sha256: 53e11ce05f3de3993c686b6a738d5991fb4965293de1ae89be10712c3ec9eee2

Contents?: true

Size: 763 Bytes

Versions: 18

Compression:

Stored size: 763 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)
    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

18 entries across 18 versions & 2 rubygems

Version Path
testcentricity_web-3.0.15 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.14 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.13 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.12 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.11 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.10 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.9 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.8 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.7 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.6 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.5 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.4 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.3 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.2 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.1 lib/testcentricity_web/utility_helpers.rb
testcentricity_web-3.0.0 lib/testcentricity_web/utility_helpers.rb
testcentricity-2.4.3 lib/testcentricity/utility_helpers.rb
testcentricity_web-2.4.3 lib/testcentricity_web/utility_helpers.rb