Class: String

Inherits:
Object show all
Defined in:
lib/unresponsys/helpers.rb

Constant Summary collapse

BLANK_RE =
/\A[[:space:]]*\z/

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/unresponsys/helpers.rb', line 63

def blank?
  BLANK_RE === self
end

#is_bool?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_boolObject



51
52
53
# File 'lib/unresponsys/helpers.rb', line 51

def to_bool
  self == 'T'
end

#to_rubyObject



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

#to_timeObject



42
43
44
# File 'lib/unresponsys/helpers.rb', line 42

def to_time
  Time.parse(self)
end