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, AddressRU, AddressSE, AddressSN, AddressUA, AddressUK, AddressUS, Airline, Avatar, BaconIpsum, Book, Boolean, CheesyLingo, Color, ColorUA, Company, CompanyCN, CompanyIT, CompanySE, Conference, CoursesFR::Mathematiques, CoursesFR::Philosophie, Currency, DizzleIpsum, Education, Food, Gender, GenderBR, GenderCN, GenderID, GenderKR, Geolocation, Guid, HTMLIpsum, HealthcareIpsum, HipsterIpsum, Identification, IdentificationBR, IdentificationES, IdentificationESCL, IdentificationESCO, IdentificationKr, IdentificationMX, Internet, InternetSE, Job, JobBR, JobCN, JobFR, JobJA, JobKR, JobVN, Locale, Lorem, LoremAR, LoremCN, LoremFR, LoremJA, LoremKR, LoremRU, LoremUA, Movie, Music, Name, NameAR, NameBR, NameCN, NameCS, NameDA, NameDE, NameFR, NameGA, NameGR, NameID, NameIT, NameJA, NameKH, NameKR, NameMX, NameNB, NameNL, NamePH, NameRU, NameSE, NameSN, NameTH, NameTHEN, NameUA, NameVN, NatoAlphabet, PhoneNumber, PhoneNumberAU, PhoneNumberBR, PhoneNumberCH, PhoneNumberCU, PhoneNumberDA, PhoneNumberDE, PhoneNumberFR, PhoneNumberID, PhoneNumberIT, PhoneNumberKR, PhoneNumberMX, PhoneNumberNL, PhoneNumberSE, PhoneNumberSG, PhoneNumberSN, Product, SSN, SSNMX, SSNSE, Skill, Sport, 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



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ffaker/utils/module_utils.rb', line 12

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).split("\n")
    const_set const_name, data
    data
  end
end

#k(arg) ⇒ Object



8
9
10
# File 'lib/ffaker/utils/module_utils.rb', line 8

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

#underscore(string) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ffaker/utils/module_utils.rb', line 24

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