lib/simplefeed/providers/redis/stats.rb
# Converts strings values of a hash into floats or integers,
# if the string matches a corresponding pattern.
Converts strings values of a hash into floats or integers,
if the string matches a corresponding pattern.
Converts strings values of a hash into floats or integers if the string matches a corresponding pattern .
def destringify(hash)
            db_hash = {}
            hash.each_pair do |key, value|
              if key =~ /^db\d+$/
                h = {}
                value.split(/,/).each do |word|
                  *words      = word.split(/=/)
                  h[words[0]] = words[1]
                end
                destringify(h)
                db_hash[key.gsub(/^db/, '').to_i] = h
                hash.delete(key)
              else
                hash[key] =
                  if value =~ /^-?\d+$/
                    value.to_i
                  elsif value =~ /^-?\d*\.\d+$/
                    value.to_f
                  else
                    value
                  end
              end
            end
            hash[:dbstats] = db_hash unless db_hash.empty?
            Hashie::Mash.new(hash)
          end
def destringify ( hash ) db_hash = { } hash . each_pair do | key , value | if key =~ / ^db \d +$ / h = { } value . split ( / , / ) . each do | word | * words = word . split ( / = / ) h [ words [ 0 ] ] = words [ 1 ] end destringify ( h ) db_hash [ key . gsub ( / ^db / , '' ) . to_i ] = h hash . delete ( key ) else hash [ key ] = if value =~ / ^-? \d +$ / value . to_i elsif value =~ / ^-? \d * \. \d +$ / value . to_f else value end end end hash [ :dbstats ] = db_hash unless db_hash . empty? Hashie :: Mash . new ( hash ) end
Converts strings values of a hash into floats or integers,
if the string matches a corresponding pattern.
Converts strings values of a hash into floats or integers if the string matches a corresponding pattern .
hash