Module: DataMaker::ModuleUtilities
- Included in:
- DataMaker, CN::Address, CN::Employment, CN::NIN, CN::Name, CN::PhoneNumber
- Defined in:
- lib/data_maker/utilities/module_utilities.rb
Instance Method Summary collapse
Instance Method Details
#const_missing(const_name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/data_maker/utilities/module_utilities.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 locale = ancestors.first.to_s.split("::")[-2] mod_name = ancestors.first.to_s.split("::").last data_path = "#{DataMaker::BASE_LIB_PATH}/data_maker/data/#{underscore(locale)}/#{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/data_maker/utilities/module_utilities.rb', line 5 def k(arg) DataMaker::ArrayUtilities.const_array(arg) end |
#underscore(string) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/data_maker/utilities/module_utilities.rb', line 22 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 |