Class: String
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #is_bool? ⇒ Boolean
- #is_f? ⇒ Boolean
- #is_i? ⇒ Boolean
- #is_time? ⇒ Boolean
- #to_bool ⇒ Object
- #to_ruby ⇒ Object
- #to_time ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
63 64 65 |
# File 'lib/unresponsys/helpers.rb', line 63 def blank? BLANK_RE === self end |
#is_bool? ⇒ Boolean
46 47 48 49 |
# File 'lib/unresponsys/helpers.rb', line 46 def is_bool? return false unless self.length == 1 %w(T F).include?(self) end |
#is_f? ⇒ Boolean
32 33 34 35 |
# File 'lib/unresponsys/helpers.rb', line 32 def is_f? return false if self.match(/e|E/) self.include?('.') && !!Float(self) rescue false end |
#is_i? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/unresponsys/helpers.rb', line 26 def is_i? return false if self.include?('.') return false if self.match(/e|E/) !!Integer(self) rescue false end |
#is_time? ⇒ Boolean
37 38 39 40 |
# File 'lib/unresponsys/helpers.rb', line 37 def is_time? return false if /[[:alpha:]]/.match(self).present? !!Time.parse(self) rescue false end |
#to_bool ⇒ Object
51 52 53 |
# File 'lib/unresponsys/helpers.rb', line 51 def to_bool self == 'T' end |
#to_ruby ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/unresponsys/helpers.rb', line 55 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 |