Class: VersionCut
- Inherits:
-
Object
- Object
- VersionCut
- Defined in:
- lib/semver_dialects/semantic_version/version_cut.rb
Instance Attribute Summary collapse
-
#semver ⇒ Object
Returns the value of attribute semver.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #!=(other_cut) ⇒ Object
- #<(other_cut) ⇒ Object
- #<=(other_cut) ⇒ Object
- #==(other_cut) ⇒ Object
- #>(other_cut) ⇒ Object
- #>=(other_cut) ⇒ Object
- #cross_total ⇒ Object
- #diff(other_cut, abs = true) ⇒ Object
-
#initialize(value, segments = nil) ⇒ VersionCut
constructor
A new instance of VersionCut.
- #is_initial_version? ⇒ Boolean
- #is_successor_of?(other_cut) ⇒ Boolean
- #major ⇒ Object
- #minor ⇒ Object
- #patch ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value, segments = nil) ⇒ VersionCut
Returns a new instance of VersionCut.
6 7 8 9 10 11 12 13 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 6 def initialize(value, segments = nil) @value = value.to_s if segments.nil? @semver = SemanticVersion.new(@value) else @semver = SemanticVersion.new(@value, segments) end end |
Instance Attribute Details
#semver ⇒ Object
Returns the value of attribute semver.
4 5 6 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 4 def semver @semver end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 4 def value @value end |
Instance Method Details
#!=(other_cut) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 66 def !=(other_cut) # self cannot be BelowAll or AboveAll if other_cut.instance_of?(BelowAll) || other_cut.instance_of?(AboveAll) false else @semver != other_cut.semver end end |
#<(other_cut) ⇒ Object
41 42 43 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 41 def <(other_cut) other_cut.instance_of?(BelowAll) ? false : other_cut.instance_of?(AboveAll) ? true : @semver < other_cut.semver end |
#<=(other_cut) ⇒ Object
49 50 51 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 49 def <=(other_cut) self < other_cut || self == other_cut end |
#==(other_cut) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 57 def ==(other_cut) # self cannot be BelowAll or AboveAll if other_cut.instance_of?(BelowAll) || other_cut.instance_of?(AboveAll) false else @semver == other_cut.semver end end |
#>(other_cut) ⇒ Object
45 46 47 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 45 def >(other_cut) other_cut.instance_of?(BelowAll) ? true : other_cut.instance_of?(AboveAll) ? false : @semver > other_cut.semver end |
#>=(other_cut) ⇒ Object
53 54 55 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 53 def >=(other_cut) self > other_cut || self == other_cut end |
#cross_total ⇒ Object
91 92 93 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 91 def cross_total [minor, major, patch].reject { |i| i.empty? }.map { |i| i.to_i }.inject(0) { |sum, x| sum + x } end |
#diff(other_cut, abs = true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 19 def diff(other_cut, abs = true) if other_cut.instance_of?(BelowAll) AboveAll.new() elsif other_cut.instance_of?(AboveAll) BelowAll.new() else diff = self.semver.diff(other_cut.semver, abs) if diff.nil? EmptyInterval.new() else VersionCut.new(diff.join("."), diff) end end end |
#is_initial_version? ⇒ Boolean
75 76 77 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 75 def is_initial_version? @semver.is_zero? end |
#is_successor_of?(other_cut) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 34 def is_successor_of?(other_cut) return true if other_cut.instance_of?(BelowAll) return false if other_cut.instance_of?(AboveAll) self.semver.is_successor_of?(other_cut.semver) end |
#major ⇒ Object
79 80 81 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 79 def major @semver.major end |
#minor ⇒ Object
83 84 85 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 83 def minor @semver.minor end |
#patch ⇒ Object
87 88 89 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 87 def patch @semver.patch end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 15 def to_s @value.to_s end |