Class: Industrialist::Type
- Inherits:
-
Object
- Object
- Industrialist::Type
- Defined in:
- lib/industrialist/type.rb
Class Method Summary collapse
- .industrialize(klass) ⇒ Object
- .separate_last_consecutive_uppercase_letter_when_followed_by_lowercase_letter(string) ⇒ Object
- .separate_lowercase_or_number_from_uppercase_letters(string) ⇒ Object
- .separate_numbers_from_letters(string) ⇒ Object
Class Method Details
.industrialize(klass) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/industrialist/type.rb', line 3 def self.industrialize(klass) str = klass.name str = separate_lowercase_or_number_from_uppercase_letters(str) str = separate_numbers_from_letters(str) str = separate_last_consecutive_uppercase_letter_when_followed_by_lowercase_letter(str) str.downcase.to_sym end |
.separate_last_consecutive_uppercase_letter_when_followed_by_lowercase_letter(string) ⇒ Object
19 20 21 |
# File 'lib/industrialist/type.rb', line 19 def self.separate_last_consecutive_uppercase_letter_when_followed_by_lowercase_letter(string) string.gsub(/[A-Z][A-Z]+[a-z]/) { |s| "#{s[0..-3]}_#{s[-2..-1]}" } end |
.separate_lowercase_or_number_from_uppercase_letters(string) ⇒ Object
11 12 13 |
# File 'lib/industrialist/type.rb', line 11 def self.separate_lowercase_or_number_from_uppercase_letters(string) string.gsub(/[a-z0-9][A-Z]+/) { |s| "#{s[0]}_#{s[1..-1]}" } end |
.separate_numbers_from_letters(string) ⇒ Object
15 16 17 |
# File 'lib/industrialist/type.rb', line 15 def self.separate_numbers_from_letters(string) string.gsub(/[a-zA-Z][0-9]+/) { |s| "#{s[0]}_#{s[1..-1]}" } end |