Method: String#sort_form
- Defined in:
- lib/libis/tools/extend/string.rb
#sort_form ⇒ Object
Create sortable object from string. Supports better natural sorting.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/libis/tools/extend/string.rb', line 12 def sort_form result = [] matcher = /^(\D*)(\d*)(.*)$/ self.split('.').each { |s| while !s.empty? and (x = matcher.match s) a = x[1].to_s.strip b = a.gsub(/[ _]/, '') result << [b.downcase, b, a] result << x[2].to_i s = x[3] end } result end |