Class: String
Instance Method Summary collapse
- #is_bool? ⇒ Boolean
- #is_f? ⇒ Boolean
- #is_i? ⇒ Boolean
- #is_time? ⇒ Boolean
- #to_bool ⇒ Object
- #to_ruby ⇒ Object
- #to_time ⇒ Object
Instance Method Details
#is_bool? ⇒ Boolean
32 33 34 35 |
# File 'lib/unresponsys/helpers.rb', line 32 def is_bool? return false unless self.length == 1 %w(T F).include?(self) end |
#is_f? ⇒ Boolean
18 19 20 21 |
# File 'lib/unresponsys/helpers.rb', line 18 def is_f? return false if self.match(/e|E/) self.include?('.') && !!Float(self) rescue false end |
#is_i? ⇒ Boolean
12 13 14 15 16 |
# File 'lib/unresponsys/helpers.rb', line 12 def is_i? return false if self.include?('.') return false if self.match(/e|E/) !!Integer(self) rescue false end |
#is_time? ⇒ Boolean
23 24 25 26 |
# File 'lib/unresponsys/helpers.rb', line 23 def is_time? return false if /[[:alpha:]]/.match(self).present? !!Time.parse(self) rescue false end |
#to_bool ⇒ Object
37 38 39 |
# File 'lib/unresponsys/helpers.rb', line 37 def to_bool self == 'T' end |
#to_ruby ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/unresponsys/helpers.rb', line 41 def to_ruby return self.to_i if self.is_i? return self.to_f if self.is_f? return self.to_time if self.is_time? return self.to_bool if self.is_bool? self end |