Module: GeoPattern::Helpers
- Defined in:
- lib/geo_pattern/helpers.rb
Class Method Summary collapse
- .build_arguments(*methods) ⇒ Object
-
.demodulize(path) ⇒ Object
Removes the module part from the expression in the string.
- .require_files_matching_pattern(pattern) ⇒ Object
-
.underscore(camel_cased_word) ⇒ Object
Makes an underscored, lowercase form from the expression in the string.
Class Method Details
.build_arguments(*methods) ⇒ Object
50 51 52 |
# File 'lib/geo_pattern/helpers.rb', line 50 def build_arguments(*methods) methods.flatten.map { |m| [m, "#{m}?"] }.flatten end |
.demodulize(path) ⇒ Object
Removes the module part from the expression in the string.
See also deconstantize
.
40 41 42 43 44 45 46 47 48 |
# File 'lib/geo_pattern/helpers.rb', line 40 def demodulize(path) path = path.to_s if (i = path.rindex("::")) path[(i + 2)..] else path end end |
.require_files_matching_pattern(pattern) ⇒ Object
5 6 7 |
# File 'lib/geo_pattern/helpers.rb', line 5 def require_files_matching_pattern(pattern) Dir.glob(pattern).sort.each { |f| require_relative f } end |
.underscore(camel_cased_word) ⇒ Object
Makes an underscored, lowercase form from the expression in the string.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/geo_pattern/helpers.rb', line 14 def underscore(camel_cased_word) return camel_cased_word unless /[A-Z-]/.match?(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.downcase! word end |