Module: FantasyFaker::BaseModule
- Included in:
- FantasyFaker, Character
- Defined in:
- lib/fantasy_faker/utils/base_module.rb
Instance Method Summary collapse
- #const_missing(const_name) ⇒ Object
- #data_path(file_name) ⇒ Object
- #module_name ⇒ Object
- #underscore(string) ⇒ Object
Instance Method Details
#const_missing(const_name) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/fantasy_faker/utils/base_module.rb', line 7 def const_missing(const_name) file_content = File.readlines(data_path(const_name)).map(&:strip) data = FantasyFaker::ArrayUtils.const_array(file_content) const_set(const_name, data) data end |
#data_path(file_name) ⇒ Object
15 16 17 |
# File 'lib/fantasy_faker/utils/base_module.rb', line 15 def data_path(file_name) "#{FantasyFaker::BASE_LIB_PATH}/fantasy_faker/data/#{underscore(module_name)}/#{underscore(file_name.to_s)}" end |
#module_name ⇒ Object
19 20 21 |
# File 'lib/fantasy_faker/utils/base_module.rb', line 19 def module_name ancestors.first.to_s.split('::').last end |
#underscore(string) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/fantasy_faker/utils/base_module.rb', line 23 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 |