Class: String

Inherits:
Object show all
Defined in:
lib/testcentricity_web/utility_helpers.rb

Instance Method Summary collapse

Instance Method Details

#format_date_time(date_time_format) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/testcentricity_web/utility_helpers.rb', line 27

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

#is_float?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/testcentricity_web/utility_helpers.rb', line 41

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

#is_int?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/testcentricity_web/utility_helpers.rb', line 37

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

#string_between(marker1, marker2) ⇒ Object



23
24
25
# File 'lib/testcentricity_web/utility_helpers.rb', line 23

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

#to_boolObject

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/testcentricity_web/utility_helpers.rb', line 17

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