Module: Unnatural::Substitution
- Defined in:
- lib/unnatural/substitution.rb
Class Method Summary collapse
Class Method Details
.compare(a, b) ⇒ Object
8 9 10 11 |
# File 'lib/unnatural/substitution.rb', line 8 def self.compare(a, b) largest = a.size < b.size ? b.size : a.size substitute(a, largest) <=> substitute(b, largest) end |
.sort(enumerable) ⇒ Object
3 4 5 6 |
# File 'lib/unnatural/substitution.rb', line 3 def self.sort(enumerable) largest = enumerable.map(&:size).max enumerable.sort_by { |s| substitute(s, largest) } end |
.substitute(string, size) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/unnatural/substitution.rb', line 13 def self.substitute(string, size) format_string = "%0#{size}d" string.downcase.gsub(/\d+/) do |m| format(format_string, m.gsub(/^0+(?=[1-9])/, '')) end end |