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.
-
#numeric_value ⇒ Object
readonly
Returns the value of attribute numeric_value.
-
#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.
- #numeric? ⇒ Boolean
- #to_normalized_s ⇒ Object
- #to_s ⇒ Object
- #wildcard? ⇒ Boolean
Constructor Details
#initialize(group_string) ⇒ SemanticVersionSegment
Returns a new instance of SemanticVersionSegment.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/semver_dialects/semantic_version.rb', line 192 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 parsed = Integer(@normalized_group_string, exception: false) @numeric_value = parsed @is_numeric = !parsed.nil? @is_wildcard = @normalized_group_string == 'X' end |
Instance Attribute Details
#is_post_release ⇒ Object
Returns the value of attribute is_post_release.
169 170 171 |
# File 'lib/semver_dialects/semantic_version.rb', line 169 def is_post_release @is_post_release end |
#is_pre_release ⇒ Object
Returns the value of attribute is_pre_release.
169 170 171 |
# File 'lib/semver_dialects/semantic_version.rb', line 169 def is_pre_release @is_pre_release end |
#normalized_group_string ⇒ Object
Returns the value of attribute normalized_group_string.
169 170 171 |
# File 'lib/semver_dialects/semantic_version.rb', line 169 def normalized_group_string @normalized_group_string end |
#numeric_value ⇒ Object (readonly)
Returns the value of attribute numeric_value.
232 233 234 |
# File 'lib/semver_dialects/semantic_version.rb', line 232 def numeric_value @numeric_value end |
#original_group_string ⇒ Object
Returns the value of attribute original_group_string.
169 170 171 |
# File 'lib/semver_dialects/semantic_version.rb', line 169 def original_group_string @original_group_string end |
Instance Method Details
#<=>(other) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/semver_dialects/semantic_version.rb', line 216 def <=>(other) return nil unless other.is_a?(SemanticVersionSegment) return 0 if @is_wildcard || other.wildcard? if @is_numeric return @numeric_value <=> other.numeric_value if other.numeric? -1 elsif other.numeric? 1 else @normalized_group_string <=> other.normalized_group_string end end |
#is_number? ⇒ Boolean
rubocop:todo Naming/PredicateName
250 251 252 |
# File 'lib/semver_dialects/semantic_version.rb', line 250 def is_number? # rubocop:todo Naming/PredicateName @is_numeric end |
#is_zero? ⇒ Boolean
rubocop:todo Naming/PredicateName
254 255 256 |
# File 'lib/semver_dialects/semantic_version.rb', line 254 def is_zero? # rubocop:todo Naming/PredicateName @is_numeric && @numeric_value.zero? end |
#numeric? ⇒ Boolean
234 235 236 |
# File 'lib/semver_dialects/semantic_version.rb', line 234 def numeric? @is_numeric end |
#to_normalized_s ⇒ Object
238 239 240 |
# File 'lib/semver_dialects/semantic_version.rb', line 238 def to_normalized_s @normalized_group_string end |
#to_s ⇒ Object
242 243 244 |
# File 'lib/semver_dialects/semantic_version.rb', line 242 def to_s @version_string end |
#wildcard? ⇒ Boolean
246 247 248 |
# File 'lib/semver_dialects/semantic_version.rb', line 246 def wildcard? @is_wildcard end |