Module: Versionize::ClassMethods

Included in:
Versionize
Defined in:
lib/versionize.rb

Instance Method Summary collapse

Instance Method Details

#major(format = :integer) ⇒ Object

The major method takes one optional argument format, indicating the type of data you want the method to return (:integer or :string). The default format is :integer. The return value includes only the :major sub-version.

Examples:

Versionize.major
=> 0

Versionize.major(:string)
=> "0"


75
76
77
78
79
80
81
82
# File 'lib/versionize.rb', line 75

def major(format=:integer)
  case format
  when :integer
    @version[:major]
  when :string
    @version[:major].to_s
  end
end

#minor(format = :integer) ⇒ Object

The minor method operates just like the major method except that its return value includes only the :minor sub-version.



91
92
93
94
95
96
97
98
# File 'lib/versionize.rb', line 91

def minor(format=:integer)
  case format
  when :integer
    @version[:minor]
  when :string
    @version[:minor].to_s
  end
end

#revision(format = :integer) ⇒ Object

The revision method operates just like the major method except that its return value includes only the :revision sub-version.



107
108
109
110
111
112
113
114
# File 'lib/versionize.rb', line 107

def revision(format=:integer)
  case format
  when :integer
    @version[:revision]
  when :string
    @version[:revision].to_s
  end
end

#version(format = :string) ⇒ Object

The version method takes one optional argument format, indicating the type of data you want the method to return (:array, :hash, or :string). The default format is :string. The return value includes all three sub-versions.

Examples:

Versionize.version
=> "0.0.1"

Versionize.version(:array)
=> [0,0,1]

Versionize.version(:hash)
=> {:major=>0,:minor=>0,:revision=>1}


48
49
50
51
52
53
54
55
56
57
# File 'lib/versionize.rb', line 48

def version(format=:string)
  case format
  when :array
    [ @version[:major], @version[:minor], @version[:revision] ]
  when :hash
    @version
  when :string
    version(:array).collect {|n| n.to_s }.join '.'
  end
end