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
48 49 50 |
# File 'lib/geo_pattern/helpers.rb', line 48 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
.
38 39 40 41 42 43 44 45 46 |
# File 'lib/geo_pattern/helpers.rb', line 38 def demodulize(path) path = path.to_s if i = path.rindex('::') path[(i + 2)..-1] else path end end |
.require_files_matching_pattern(pattern) ⇒ Object
3 4 5 |
# File 'lib/geo_pattern/helpers.rb', line 3 def require_files_matching_pattern(pattern) Dir.glob(pattern).each { |f| require_relative f } end |
.underscore(camel_cased_word) ⇒ Object
Makes an underscored, lowercase form from the expression in the string.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/geo_pattern/helpers.rb', line 12 def underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]/ word = camel_cased_word.to_s word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.downcase! word end |