module DataMaker

Constants

BASE_LIB_PATH
HEX
LETTERS
VERSION

Public Class Methods

alphanumerify(masks) click to toggle source
# File lib/data_maker.rb, line 61
def self.alphanumerify(masks)
  letterify(numerify(masks))
end
hexify(*masks) click to toggle source
# File lib/data_maker.rb, line 31
def self.hexify(*masks)
  begin
    if valid_mask?(*masks, /#/)
      masks.flatten.sample.gsub(/#/) { HEX.sample }
    end
  rescue
    return false
  end
end
letterify(*masks) click to toggle source
# File lib/data_maker.rb, line 51
def self.letterify(*masks)
  begin
    if valid_mask?(*masks, /\?/)
      masks.flatten.sample.gsub(/\?/) { LETTERS.sample }
    end
  rescue
    return false
  end
end
numerify(*masks) click to toggle source
# File lib/data_maker.rb, line 41
def self.numerify(*masks)
  begin
    if valid_mask?(*masks, /#/)
      masks.flatten.sample.gsub(/#/) { rand(10).to_s }
    end
  rescue
    return false
  end
end
translate(*args) click to toggle source
# File lib/data_maker.rb, line 65
def self.translate(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options[:locale] ||= DataMaker::Config.locale
  options[:raise] = true
  I18n.translate(*(args.push(options)))
  rescue I18n::MissingTranslationData
  I18n.translate(*(args.push(options.merge(locale: :en))))
end

Private Class Methods

valid_mask?(*masks, match_with) click to toggle source
# File lib/data_maker.rb, line 79
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