Sha256: 9da89e47407494ed4c608e3de4ab37f63fe349b356576f9ac3620015153c3bcb

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module DataMaker
  VERSION = "2.2.3"

  require 'data_maker/utilities/array_utilities'
  require 'data_maker/utilities/module_utilities'

  extend ModuleUtilities

  BASE_LIB_PATH = File.expand_path("..", __FILE__)

  LETTERS = [*'a'..'z']

  HEX = %w(0 1 2 3 4 5 6 7 8 9 A B C D E F)

  def self.hexify(*masks)
    begin
      if valid_mask?(*masks, /#/)
        masks.flatten.sample.gsub(/#/) { HEX.sample }
      end
    rescue
      return false
    end
  end

  def self.numerify(*masks)
    begin
      if valid_mask?(*masks, /#/)
        masks.flatten.sample.gsub(/#/) { rand(10).to_s }
      end
    rescue
      return false
    end
  end

  def self.letterify(*masks)
    begin
      if valid_mask?(*masks, /\?/)
        masks.flatten.sample.gsub(/\?/) { LETTERS.sample }
      end
    rescue
      return false
    end
  end

  def self.alphanumerify(masks)
    letterify(numerify(masks))
  end

  # Load all constants.
  Dir["#{BASE_LIB_PATH}/data_maker/**/*.rb"].sort.each do |f|
    require f
  end

  def self.valid_mask?(*masks, match_with)
    masks.each do |mask|
      unless mask.match(match_with)
        raise ArgumentError, "You must pass a #{match_with} sign sir!"
      end
    end
  end

  private_class_method :valid_mask?
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_maker-2.2.3 lib/data_maker.rb