Module: Faker::ModuleUtils
- Included in:
- Faker, Address, AddressAU, AddressBR, AddressCA, AddressDA, AddressDE, AddressFI, AddressFR, AddressMX, AddressNL, AddressSE, AddressSN, AddressUK, AddressUS, BaconIpsum, Boolean, Color, Company, CompanyIT, CompanySE, Conference, CoursesFR::Mathematiques, CoursesFR::Philosophie, Currency, DizzleIpsum, Education, Food, Gender, GenderCN, GenderKR, Geolocation, Guid, HTMLIpsum, HealthcareIpsum, HipsterIpsum, Identification, IdentificationES, IdentificationESCO, IdentificationMX, Internet, InternetSE, Job, JobFR, JobJA, JobKR, Locale, Lorem, LoremAR, LoremCN, LoremFR, LoremKR, Movie, Name, NameBR, NameCN, NameCS, NameDA, NameDE, NameFR, NameGA, NameIT, NameJA, NameKR, NameMX, NameNB, NameNL, NamePH, NameRU, NameSE, NameSN, NameTH, NameVN, NatoAlphabet, PhoneNumber, PhoneNumberAU, PhoneNumberCU, PhoneNumberDA, PhoneNumberDE, PhoneNumberFR, PhoneNumberIT, PhoneNumberKR, PhoneNumberMX, PhoneNumberNL, PhoneNumberSE, PhoneNumberSG, PhoneNumberSN, Product, SSN, SSNMX, SSNSE, Skill, String, Time, Unit, UnitEnglish, UnitMetric, Vehicle, Venue
- Defined in:
- lib/ffaker/utils/module_utils.rb
Instance Method Summary collapse
Instance Method Details
#const_missing(const_name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ffaker/utils/module_utils.rb', line 9 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 = "#{Faker::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
5 6 7 |
# File 'lib/ffaker/utils/module_utils.rb', line 5 def k(arg) Faker::ArrayUtils.const_array(arg) end |
#underscore(string) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/ffaker/utils/module_utils.rb', line 21 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 |