Class: SemverDialects::SemanticVersionSegment
- Inherits:
-
Object
- Object
- SemverDialects::SemanticVersionSegment
- Includes:
- Comparable
- Defined in:
- lib/semver_dialects/semantic_version.rb
Overview
rubocop:todo Style/Documentation
Constant Summary collapse
- @@group_suffixes =
rubocop:todo Style/ClassVars
{ # rubocop:todo Style/ClassVars # pre-releases 'PRE' => -16, 'PREVIEW' => -16, 'DEV' => -15, 'A' => -14, 'ALPHA' => -13, 'B' => -12, 'BETA' => -12, 'RC' => -11, 'M' => -10, 'RELEASE' => 0, 'FINAL' => 0, # PHP specific 'STABLE' => 0, # post-releases 'SP' => 1 }
Instance Attribute Summary collapse
-
#is_post_release ⇒ Object
Returns the value of attribute is_post_release.
-
#is_pre_release ⇒ Object
Returns the value of attribute is_pre_release.
-
#normalized_group_string ⇒ Object
Returns the value of attribute normalized_group_string.
-
#original_group_string ⇒ Object
Returns the value of attribute original_group_string.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(group_string) ⇒ SemanticVersionSegment
constructor
A new instance of SemanticVersionSegment.
-
#is_number? ⇒ Boolean
rubocop:todo Naming/PredicateName.
-
#is_zero? ⇒ Boolean
rubocop:todo Naming/PredicateName.
- #to_normalized_s ⇒ Object
- #to_s ⇒ Object
- #wildcard? ⇒ Boolean
Constructor Details
#initialize(group_string) ⇒ SemanticVersionSegment
Returns a new instance of SemanticVersionSegment.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/semver_dialects/semantic_version.rb', line 172 def initialize(group_string) @is_post_release = false @is_pre_release = false @version_string = group_string @original_group_string = group_string # use x as unique placeholder group_string_ucase = group_string.to_s.gsub(/\*/, 'x').upcase if @@group_suffixes.key?(group_string_ucase) value = @@group_suffixes[group_string_ucase] @is_post_release = value.positive? @is_pre_release = value.negative? @normalized_group_string = @@group_suffixes[group_string_ucase].to_s else @normalized_group_string = group_string_ucase end end |
Instance Attribute Details
#is_post_release ⇒ Object
Returns the value of attribute is_post_release.
149 150 151 |
# File 'lib/semver_dialects/semantic_version.rb', line 149 def is_post_release @is_post_release end |
#is_pre_release ⇒ Object
Returns the value of attribute is_pre_release.
149 150 151 |
# File 'lib/semver_dialects/semantic_version.rb', line 149 def is_pre_release @is_pre_release end |
#normalized_group_string ⇒ Object
Returns the value of attribute normalized_group_string.
149 150 151 |
# File 'lib/semver_dialects/semantic_version.rb', line 149 def normalized_group_string @normalized_group_string end |
#original_group_string ⇒ Object
Returns the value of attribute original_group_string.
149 150 151 |
# File 'lib/semver_dialects/semantic_version.rb', line 149 def original_group_string @original_group_string end |
Instance Method Details
#<=>(other) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/semver_dialects/semantic_version.rb', line 191 def <=>(other) return nil unless other.is_a?(SemanticVersionSegment) self_semver = normalized_group_string other_semver = other.normalized_group_string both_are_numbers = self_semver.number? && other_semver.number? at_least_one_is_x = self_semver == 'X' || other_semver == 'X' a_numeric_b_non_numeric = self_semver.number? && !other_semver.number? b_numeric_a_non_numeric = other_semver.number? && !self_semver.number? if both_are_numbers self_semver.to_i <=> other_semver.to_i elsif at_least_one_is_x 0 elsif a_numeric_b_non_numeric -1 elsif b_numeric_a_non_numeric 1 else self_semver <=> other_semver end end |
#is_number? ⇒ Boolean
rubocop:todo Naming/PredicateName
227 228 229 |
# File 'lib/semver_dialects/semantic_version.rb', line 227 def is_number? # rubocop:todo Naming/PredicateName normalized_group_string.number? end |
#is_zero? ⇒ Boolean
rubocop:todo Naming/PredicateName
231 232 233 |
# File 'lib/semver_dialects/semantic_version.rb', line 231 def is_zero? # rubocop:todo Naming/PredicateName is_number? ? normalized_group_string.to_i.zero? : false end |
#to_normalized_s ⇒ Object
215 216 217 |
# File 'lib/semver_dialects/semantic_version.rb', line 215 def to_normalized_s @normalized_group_string end |
#to_s ⇒ Object
219 220 221 |
# File 'lib/semver_dialects/semantic_version.rb', line 219 def to_s @version_string end |
#wildcard? ⇒ Boolean
223 224 225 |
# File 'lib/semver_dialects/semantic_version.rb', line 223 def wildcard? normalized_group_string == 'X' end |