Sha256: c54ca6fdf1ff1a18a699c7db9927e1138861cb3ccbb4fa1fc2d92cc5bb3b5c91

Contents?: true

Size: 915 Bytes

Versions: 3

Compression:

Stored size: 915 Bytes

Contents

require 'demode/generator/person'
require 'demode/generator/company'
require 'demode/generator/fields'
require 'digest'

module Demode
  module Generate
    class << self

      def get(id, field)
        if Generator.respond_to? field
          return Generator.send(field, normalize_id(id))
        end
      end

      def normalize_id(id)
        Digest::MD5.hexdigest( sigflat id ).hex
      end

      def sigflat(id)
        if id.class == Hash
          arr = []
          id.each do |key, value|
            arr << "#{sigflat key}=>#{sigflat value}"
          end
          id = arr
        end
        if id.class == Array
          str = ''
          id.map! do |value|
            sigflat value
          end.sort!.each do |value|
            str << value
          end
        end
        if id.class != String
          id = id.to_s << id.class.to_s
        end
        id
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
demode-0.0.3 lib/demode/generate.rb
demode-0.0.2 lib/demode/generate.rb
demode-0.0.1 lib/demode/generate.rb