Module: NaturallyUnicode
- Defined in:
- lib/naturally-unicode.rb,
lib/naturally-unicode/version.rb
Defined Under Namespace
Classes: NumberElement
Constant Summary collapse
- VERSION =
"1.1.0"
Class Method Summary collapse
-
.normalize(number) ⇒ Array<NumberElement>
Convert the given number into an object that can be sorted naturally.
-
.sort(an_array) ⇒ Array<String>
Perform a natural sort.
Class Method Details
.normalize(number) ⇒ Array<NumberElement>
Convert the given number into an object that can be sorted naturally. This object is an array of NumberElement instances.
18 19 20 |
# File 'lib/naturally-unicode.rb', line 18 def self.normalize(number) number.to_s.scan(%r/\p{Word}+/o).map { |i| NumberElement.new(i) } end |
.sort(an_array) ⇒ Array<String>
Perform a natural sort.
8 9 10 |
# File 'lib/naturally-unicode.rb', line 8 def self.sort(an_array) return an_array.sort_by { |x| normalize(x) } end |