Class: NSWTopo::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nswtopo/version.rb

Constant Summary collapse

Error =
Class.new StandardError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digit_string) ⇒ Version

Returns a new instance of Version.



15
16
17
18
# File 'lib/nswtopo/version.rb', line 15

def initialize(digit_string)
  @to_s = digit_string
  @to_a = digit_string.split(?.).map(&:to_i)
end

Instance Attribute Details

#to_aObject (readonly)

Returns the value of attribute to_a.



20
21
22
# File 'lib/nswtopo/version.rb', line 20

def to_a
  @to_a
end

#to_sObject (readonly)

Returns the value of attribute to_s.



20
21
22
# File 'lib/nswtopo/version.rb', line 20

def to_s
  @to_s
end

Class Method Details

.[](creator_string) ⇒ Object



6
7
8
9
# File 'lib/nswtopo/version.rb', line 6

def self.[](creator_string)
  /^nswtopo (?<digit_string>\d+(\.\d+(\.\d+)?)?)$/ =~ creator_string.to_s
  digit_string ? new(digit_string) : raise(Error)
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
# File 'lib/nswtopo/version.rb', line 22

def <=>(other)
  self.to_a <=> other.to_a
end

#creator_stringObject



11
12
13
# File 'lib/nswtopo/version.rb', line 11

def creator_string
  "nswtopo #{self}"
end