Class: NaturalSort::Segment
- Inherits:
-
Object
- Object
- NaturalSort::Segment
- Includes:
- Comparable
- Defined in:
- lib/natural_sort/segment.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(input) ⇒ Segment
constructor
A new instance of Segment.
- #numeric? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(input) ⇒ Segment
Returns a new instance of Segment.
12 13 14 |
# File 'lib/natural_sort/segment.rb', line 12 def initialize(input) @input = input.to_s end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
10 11 12 |
# File 'lib/natural_sort/segment.rb', line 10 def input @input end |
Instance Method Details
#<=>(other) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/natural_sort/segment.rb', line 20 def <=>(other) if numeric? && other.numeric? Rational(input) <=> Rational(other.to_s) else compare_chars(input, other.to_s) end end |
#numeric? ⇒ Boolean
28 29 30 |
# File 'lib/natural_sort/segment.rb', line 28 def numeric? NUMERIC === input end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/natural_sort/segment.rb', line 16 def to_s @input end |