Class: FunWith::VersionStrings::VersionString

Inherits:
String
  • Object
show all
Defined in:
lib/version_strings/version_string.rb

Constant Summary collapse

FORMAT_VALIDATOR =
/^(?:(?<major>\d+)\.?)?(?:(?<minor>\d+)\.?)?(?:(?<patch>\d+))?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#fwvs_version_string

Constructor Details

#initialize(src) ⇒ VersionString

version must be of format n.nn or n.nn.nn

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/version_strings/version_string.rb', line 9

def initialize( src )
  @match_data = src.match( FORMAT_VALIDATOR )
  raise ArgumentError.new( "Not a valid version format for a VersionString." ) if @match_data.nil?

  @major = (@match_data[:major] || 0).to_i
  @minor = (@match_data[:minor] || 0).to_i
  @patch = (@match_data[:patch] || 0).to_i
  
  super( "#{@major}.#{@minor}.#{@patch}" )
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



5
6
7
# File 'lib/version_strings/version_string.rb', line 5

def major
  @major
end

#minorObject

Returns the value of attribute minor.



5
6
7
# File 'lib/version_strings/version_string.rb', line 5

def minor
  @minor
end

#patchObject Also known as: tiny

Returns the value of attribute patch.



5
6
7
# File 'lib/version_strings/version_string.rb', line 5

def patch
  @patch
end