Class: Spout::Helpers::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/spout/helpers/semantic.rb

Overview

Helps to sort semantically versioned numbers to match versions that are close to each other.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Version

Returns a new instance of Version.



11
12
13
14
# File 'lib/spout/helpers/semantic.rb', line 11

def initialize(string)
  @string = string.to_s
  (@major, @minor, @tiny, @build) = @string.split(".")
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



9
10
11
# File 'lib/spout/helpers/semantic.rb', line 9

def build
  @build
end

#majorObject (readonly)

Returns the value of attribute major.



9
10
11
# File 'lib/spout/helpers/semantic.rb', line 9

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



9
10
11
# File 'lib/spout/helpers/semantic.rb', line 9

def minor
  @minor
end

#stringObject

Returns the value of attribute string.



8
9
10
# File 'lib/spout/helpers/semantic.rb', line 8

def string
  @string
end

#tinyObject (readonly)

Returns the value of attribute tiny.



9
10
11
# File 'lib/spout/helpers/semantic.rb', line 9

def tiny
  @tiny
end

Instance Method Details

#build_numberObject



28
29
30
# File 'lib/spout/helpers/semantic.rb', line 28

def build_number
  (@build.nil? ? 1 : 0)
end

#major_numberObject



16
17
18
# File 'lib/spout/helpers/semantic.rb', line 16

def major_number
  @major.to_i
end

#minor_numberObject



20
21
22
# File 'lib/spout/helpers/semantic.rb', line 20

def minor_number
  @minor.to_i
end

#rankObject



32
33
34
# File 'lib/spout/helpers/semantic.rb', line 32

def rank
  [major_number, minor_number, tiny_number, build_number]
end

#tiny_numberObject



24
25
26
# File 'lib/spout/helpers/semantic.rb', line 24

def tiny_number
  @tiny.to_i
end