Class: SemverStringer::Semver::Substring
- Inherits:
-
Object
- Object
- SemverStringer::Semver::Substring
- Includes:
- Comparable
- Defined in:
- lib/semver_stringer/semver.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(s) ⇒ Substring
constructor
A new instance of Substring.
Constructor Details
#initialize(s) ⇒ Substring
Returns a new instance of Substring.
9 10 11 |
# File 'lib/semver_stringer/semver.rb', line 9 def initialize(s) @str = s end |
Class Method Details
.compare_version_atoms(first, second) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/semver_stringer/semver.rb', line 37 def self.compare_version_atoms(first, second) if first == nil and second == nil return nil elsif first != nil and second == nil return 1 elsif first == nil and second != nil return -1 else unless first.match /[^0-9]/ or second.match /[^0-9]/ return first.to_i <=> second.to_i else return first <=> second end end end |
.compareVersionStrings(first, second) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/semver_stringer/semver.rb', line 18 def self.compareVersionStrings(first, second) first_components = first.split('.') second_components = second.split('.') first_head = first_components.shift second_head = second_components.shift head_comparison = compare_version_atoms first_head, second_head if head_comparison == 0 if first_components.length > 0 or second_components.length > 0 return Substring::compareVersionStrings first_components.join('.'), second_components.join('.') else return 0 end else return head_comparison end end |
Instance Method Details
#<=>(other) ⇒ Object
13 14 15 16 |
# File 'lib/semver_stringer/semver.rb', line 13 def <=>(other) other_str = other.instance_variable_get('@str') return Substring::compareVersionStrings @str, other_str end |