Class: String
Instance Method Summary collapse
- #format_date_time(date_time_format) ⇒ Object
- #string_between(marker1, marker2) ⇒ Object
- #to_bool ⇒ Object
Instance Method Details
#format_date_time(date_time_format) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/testcentricity_web/utility_helpers.rb', line 23 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 |
#string_between(marker1, marker2) ⇒ Object
19 20 21 |
# File 'lib/testcentricity_web/utility_helpers.rb', line 19 def string_between(marker1, marker2) self[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1] end |
#to_bool ⇒ Object
13 14 15 16 17 |
# File 'lib/testcentricity_web/utility_helpers.rb', line 13 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 |