Module: FFaker::ModuleUtils

Includes:
RandomUtils
Included in:
FFaker, AWS, Address, AddressAU, AddressBR, AddressCA, AddressCH, AddressCHDE, AddressCHFR, AddressCHIT, AddressDA, AddressDE, AddressFI, AddressFR, AddressGR, AddressID, AddressIN, AddressJA, AddressKR, AddressMX, AddressNL, AddressPL, AddressRU, AddressSE, AddressSN, AddressUA, AddressUK, AddressUS, Airline, Animal, AnimalCN, AnimalES, AnimalPL, AnimalUS, Avatar, BaconIpsum, Bank, Book, Boolean, CheesyLingo, Code, Color, ColorPL, ColorUA, Company, CompanyCN, CompanyIT, CompanyJA, CompanySE, Conference, CoursesFR::Mathematiques, CoursesFR::Philosophie, Currency, DizzleIpsum, Education, EducationCN, Filesystem, Food, Gender, GenderBR, GenderCN, GenderID, GenderJA, GenderJP, GenderKR, GenderPL, Geolocation, Guid, HTMLIpsum, HealthcareIpsum, HealthcareRU, HipsterIpsum, Identification, IdentificationBR, IdentificationES, IdentificationESCL, IdentificationESCO, IdentificationIN, IdentificationKr, IdentificationMX, IdentificationPL, IdentificationTW, Image, Internet, InternetSE, Job, JobBR, JobCN, JobFR, JobJA, JobKR, JobVN, Locale, Lorem, LoremAR, LoremCN, LoremFR, LoremIE, LoremJA, LoremKR, LoremPL, LoremRU, LoremUA, Movie, Music, Name, NameAR, NameBR, NameCN, NameCS, NameDA, NameDE, NameES, NameFR, NameGA, NameGR, NameID, NameIN, NameIT, NameJA, NameKH, NameKR, NameMX, NameNB, NameNL, NamePH, NamePL, NameRU, NameSE, NameSN, NameTH, NameTHEN, NameTW, NameUA, NameVN, NatoAlphabet, PhoneNumber, PhoneNumberAU, PhoneNumberBR, PhoneNumberCH, PhoneNumberCU, PhoneNumberDA, PhoneNumberDE, PhoneNumberFR, PhoneNumberID, PhoneNumberIT, PhoneNumberKR, PhoneNumberMX, PhoneNumberNL, PhoneNumberPL, PhoneNumberRU, PhoneNumberSE, PhoneNumberSG, PhoneNumberSN, PhoneNumberTW, PhoneNumberUA, Product, SSN, SSNMX, SSNSE, SemVer, Skill, Sport, SportPL, SportUS, String, Time, Tweet, Unit, UnitEnglish, UnitMetric, Vehicle, Venue, Youtube
Defined in:
lib/ffaker/utils/module_utils.rb

Instance Method Summary collapse

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#const_missing(const_name) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ffaker/utils/module_utils.rb', line 15

def const_missing(const_name)
  if const_name =~ /[a-z]/ # Not a constant, probably a class/module name.
    super const_name
  else
    mod_name = ancestors.first.to_s.split('::').last
    data_path = "#{FFaker::BASE_LIB_PATH}/ffaker/data/#{underscore(mod_name)}/#{underscore(const_name.to_s)}"
    data = k File.read(data_path, mode: 'r:UTF-8').split("\n")
    const_set const_name, data
    data
  end
end

#k(arg) ⇒ Object


11
12
13
# File 'lib/ffaker/utils/module_utils.rb', line 11

def k(arg)
  FFaker::ArrayUtils.const_array(arg)
end

#underscore(string) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/ffaker/utils/module_utils.rb', line 27

def underscore(string)
  string.gsub(/::/, '/')
        .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
        .gsub(/([a-z\d])([A-Z])/, '\1_\2')
        .tr('-', '_')
        .downcase
end

#unique(max_retries = 10_000) ⇒ Object


35
36
37
# File 'lib/ffaker/utils/module_utils.rb', line 35

def unique(max_retries = 10_000)
  @unique_generator ||= FFaker::UniqueUtils.new(self, max_retries)
end