Class: Hackle::MetadataVersion
- Inherits:
-
Object
- Object
- Hackle::MetadataVersion
- Includes:
- Comparable
- Defined in:
- lib/hackle/internal/model/version.rb
Instance Attribute Summary collapse
-
#identifiers ⇒ Object
readonly
Returns the value of attribute identifiers.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #compare_identifiers(other) ⇒ Object
- #compare_single_identifier(id1, id2) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(identifiers) ⇒ MetadataVersion
constructor
A new instance of MetadataVersion.
- #to_s ⇒ Object
Constructor Details
#initialize(identifiers) ⇒ MetadataVersion
Returns a new instance of MetadataVersion.
104 105 106 |
# File 'lib/hackle/internal/model/version.rb', line 104 def initialize(identifiers) @identifiers = identifiers end |
Instance Attribute Details
#identifiers ⇒ Object (readonly)
Returns the value of attribute identifiers.
102 103 104 |
# File 'lib/hackle/internal/model/version.rb', line 102 def identifiers @identifiers end |
Class Method Details
.parse(value) ⇒ Object
108 109 110 111 112 |
# File 'lib/hackle/internal/model/version.rb', line 108 def self.parse(value) return new([]) unless value new(value.split('.')) end |
Instance Method Details
#<=>(other) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/hackle/internal/model/version.rb', line 118 def <=>(other) return 0 if empty? && other.empty? return -1 if empty? return 1 if other.empty? compare_identifiers(other) end |
#==(other) ⇒ Object
114 115 116 |
# File 'lib/hackle/internal/model/version.rb', line 114 def ==(other) other.is_a?(MetadataVersion) && identifiers == other.identifiers end |
#compare_identifiers(other) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/hackle/internal/model/version.rb', line 126 def compare_identifiers(other) min_length = [identifiers.length, other.identifiers.length].min min_length.times do |i| result = compare_single_identifier(identifiers[i], other.identifiers[i]) return result if result != 0 end identifiers.length <=> other.identifiers.length end |
#compare_single_identifier(id1, id2) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/hackle/internal/model/version.rb', line 135 def compare_single_identifier(id1, id2) num1 = id1.to_i num2 = id2.to_i if id1.to_i.to_s == id1 && id2.to_i.to_s == id2 num1 <=> num2 else id1 <=> id2 end end |
#empty? ⇒ Boolean
149 150 151 |
# File 'lib/hackle/internal/model/version.rb', line 149 def empty? identifiers.empty? end |
#to_s ⇒ Object
145 146 147 |
# File 'lib/hackle/internal/model/version.rb', line 145 def to_s identifiers.join('.') end |