lib/dbx.rb
# Detect the column type given a value.
# May return nil if the value is blank.
Detect the column type given a value.
May return nil if the value is blank.
Detect the column type given a value . May return nil if the value is blank .
def detect_type(value)
    if value.blank?
      nil
    elsif value =~ /^\d+\.\d+$/
      :decimal
    elsif value =~ /^\d{1,10}$/
      :integer
    elsif value =~ /^\h{8}-\h{4}-\h{4}-\h{4}-\h{12}$/
      :uuid
    elsif value =~ /^\d{4}(\D)\d{2}\1\d{2}$/ && (Date.parse(value) rescue false)
      :date
    elsif (Time.parse(value) rescue false)
      :datetime
    else
      :string
    end
  end
def detect_type ( value ) if value . blank? nil elsif value =~ / ^ \d + \. \d +$ / :decimal elsif value =~ / ^ \d {1,10}$ / :integer elsif value =~ / ^ \h {8}- \h {4}- \h {4}- \h {4}- \h {12}$ / :uuid elsif value =~ / ^ \d {4}( \D ) \d {2} \1 \d {2}$ / && ( Date . parse ( value ) rescue false ) :date elsif ( Time . parse ( value ) rescue false ) :datetime else :string end end
Detect the column type given a value.
Detect the column type given a value .
value
<not_specific>