Class: String

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

Instance Method Summary collapse

Instance Method Details

#is_bool?Boolean

Returns:

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

Returns:

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

Returns:

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

Returns:

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



37
38
39
# File 'lib/unresponsys/helpers.rb', line 37

def to_bool
  self == 'T'
end

#to_rubyObject



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

#to_timeObject



28
29
30
# File 'lib/unresponsys/helpers.rb', line 28

def to_time
  Time.parse(self)
end