Class: String

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

Instance Method Summary collapse

Instance Method Details

#is_bool?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/unresponsys/helpers.rb', line 30

def is_bool?
  return false unless self.length == 1
  %w(T F).include?(self)
end

#is_f?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/unresponsys/helpers.rb', line 17

def is_f?
  !!Float(self) rescue false
end

#is_i?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/unresponsys/helpers.rb', line 12

def is_i?
  return false if self.include?('.')
  !!Integer(self) rescue false
end

#is_time?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/unresponsys/helpers.rb', line 21

def is_time?
  return false if /[[:alpha:]]/.match(self).present?
  !!Time.parse(self) rescue false
end

#to_boolObject



35
36
37
# File 'lib/unresponsys/helpers.rb', line 35

def to_bool
  self == 'T'
end

#to_rubyObject



39
40
41
42
43
44
45
# File 'lib/unresponsys/helpers.rb', line 39

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



26
27
28
# File 'lib/unresponsys/helpers.rb', line 26

def to_time
  Time.parse(self)
end