Class: VersionCut

Inherits:
Object
  • Object
show all
Defined in:
lib/semver_dialects/semantic_version/version_cut.rb

Direct Known Subclasses

AboveAll, BelowAll

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#semverObject

Returns the value of attribute semver.



4
5
6
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 4

def semver
  @semver
end

#valueObject

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_totalObject



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

Returns:

  • (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

Returns:

  • (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

#majorObject



79
80
81
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 79

def major
  @semver.major
end

#minorObject



83
84
85
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 83

def minor
  @semver.minor
end

#patchObject



87
88
89
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 87

def patch
  @semver.patch
end

#to_sObject



15
16
17
# File 'lib/semver_dialects/semantic_version/version_cut.rb', line 15

def to_s
  @value.to_s
end