Class: VersionHelper::Version
- Inherits:
-
Object
- Object
- VersionHelper::Version
- Defined in:
- lib/rubyhelper/versionhelper.rb
Instance Attribute Summary collapse
-
#v ⇒ Object
Returns the value of attribute v.
Class Method Summary collapse
-
.to_a(version) ⇒ Object
Return an array with each number of the version.
-
.to_h(version) ⇒ Object
Not work.
-
.to_i(version) ⇒ Object
Return an integer with each number of the version.
-
.to_s(version) ⇒ Object
Return an string with each number of the version, joined by ‘.’.
Instance Method Summary collapse
- #decr!(n = -1)) ⇒ Object
- #incr!(n = -1)) ⇒ Object
-
#initialize(*arg) ⇒ Version
constructor
Params: arg : list of arguments Integer : 1234 => 1.2.3.4 String : “1.2-3” => 1.2.3 Array : like multiple arguments multiple : each argument is converted to a number 1,2,3 => 1.2.3.
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*arg) ⇒ Version
Params:
arg : list of arguments Integer : 1234 => 1.2.3.4 String : “1.2-3” => 1.2.3 Array : like multiple arguments multiple : each argument is converted to a number 1,2,3 => 1.2.3
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubyhelper/versionhelper.rb', line 18 def initialize(*arg) @v = [] if arg.size == 1 v = arg.first case v.class.to_s when 'String' v.gsub!(/\A\D/, '') v.gsub!(/\D/, '.') @v = v.split('.').map{|e| e.to_i} when 'Array' @v = v.map{|e| e.to_i} when 'Fixnum' v = v.to_i loop do break if v == 0 @v << (v % 10) v /= 10 end else raise ArgumentError, v.class.to_s end end if arg.size > 1 @v = arg.map{|e| e.to_i} end end |
Instance Attribute Details
#v ⇒ Object
Returns the value of attribute v.
9 10 11 |
# File 'lib/rubyhelper/versionhelper.rb', line 9 def v @v end |
Class Method Details
.to_a(version) ⇒ Object
Return an array with each number of the version
70 71 72 73 |
# File 'lib/rubyhelper/versionhelper.rb', line 70 def self.to_a(version) raise ArgumentError unless version.is_a? Version return version.v.dup end |
.to_h(version) ⇒ Object
Not work
82 83 84 85 |
# File 'lib/rubyhelper/versionhelper.rb', line 82 def self.to_h(version) raise ArgumentError unless version.is_a? Version return nil end |
.to_i(version) ⇒ Object
Return an integer with each number of the version
88 89 90 91 92 93 |
# File 'lib/rubyhelper/versionhelper.rb', line 88 def self.to_i(version) raise ArgumentError unless version.is_a? Version i = 0 version.v.each{|e| i = i * 10 + e} return i end |
.to_s(version) ⇒ Object
Return an string with each number of the version, joined by ‘.’
76 77 78 79 |
# File 'lib/rubyhelper/versionhelper.rb', line 76 def self.to_s(version) raise ArgumentError unless version.is_a? Version return version.v.join('.') end |
Instance Method Details
#decr!(n = -1)) ⇒ Object
49 50 51 |
# File 'lib/rubyhelper/versionhelper.rb', line 49 def decr!(n=-1) @v[n] = @v[n] -= 1 end |
#incr!(n = -1)) ⇒ Object
45 46 47 |
# File 'lib/rubyhelper/versionhelper.rb', line 45 def incr!(n=-1) @v[n] = @v[n] += 1 end |
#to_a ⇒ Object
53 54 55 |
# File 'lib/rubyhelper/versionhelper.rb', line 53 def to_a return Version.to_a(self) end |
#to_h ⇒ Object
61 62 63 |
# File 'lib/rubyhelper/versionhelper.rb', line 61 def to_h return Version.to_h(self) end |