class SimpleRewriter::TypeDetector

Attributes

attr_value[R]

Public Class Methods

new(attr_value) click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 3
def initialize(attr_value)
  @attr_value = attr_value
end

Public Instance Methods

call() click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 7
def call
  detect_type
end

Private Instance Methods

date?() click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 26
def date?
  Date.parse(attr_value) if string?
rescue ArgumentError
  false
end
detect_type() click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 15
def detect_type
  return Integer if integer?
  return Date if date?
  return Float if float?
end
float?() click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 32
def float?
  return attr_value.match?(/[0-9]+[.]{1}[0-9]+/) if attr_value.respond_to?(:match?)
  false
end
integer?() click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 21
def integer?
  return attr_value.match?(/\A[-+]?[0-9]+\z/) if attr_value.respond_to?(:match?)
  false
end
string?() click to toggle source
# File lib/simple_rewriter/type_detector.rb, line 37
def string?
  attr_value.is_a?(String)
end