Class: TingYun::Support::VersionNumber

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ting_yun/support/version_number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ VersionNumber

Returns a new instance of VersionNumber.



11
12
13
14
# File 'lib/ting_yun/support/version_number.rb', line 11

def initialize(version_string)
  version_string ||= '1.0.0'
  @parts = version_string.split('.').map { |n| n =~ /^\d+$/ ? n.to_i : n }
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



9
10
11
# File 'lib/ting_yun/support/version_number.rb', line 9

def parts
  @parts
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
31
# File 'lib/ting_yun/support/version_number.rb', line 28

def <=>(other)
  other = self.class.new(other) if other.is_a? String
  self.class.compare(self.parts, other.parts)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ting_yun/support/version_number.rb', line 41

def eql? other
  (self <=> other) == 0
end

#hashObject



37
38
39
# File 'lib/ting_yun/support/version_number.rb', line 37

def hash
  @parts.hash
end

#major_versionObject



16
17
18
# File 'lib/ting_yun/support/version_number.rb', line 16

def major_version;
  @parts[0];
end

#minor_versionObject



20
21
22
# File 'lib/ting_yun/support/version_number.rb', line 20

def minor_version;
  @parts[1];
end

#tiny_versionObject



24
25
26
# File 'lib/ting_yun/support/version_number.rb', line 24

def tiny_version;
  @parts[2];
end

#to_sObject



33
34
35
# File 'lib/ting_yun/support/version_number.rb', line 33

def to_s
  @parts.join(".")
end