Class: Gemspec::Version
- Inherits:
-
Object
- Object
- Gemspec::Version
- Defined in:
- lib/gemspec/bump.rb
Constant Summary collapse
- IllegalFormat =
Class.new(ArgumentError)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #apply(diff) ⇒ Object
-
#initialize(string_or_array) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(string_or_array) ⇒ Version
Returns a new instance of Version.
9 10 11 12 13 14 |
# File 'lib/gemspec/bump.rb', line 9 def initialize(string_or_array) @data = string_or_array @data = @data.split('.') if string_or_array.is_a? String raise IllegalFormat, to_s unless @data.all? {|item| item.is_a? Integer or item =~ /^\d*$/ } @data.map!(&:to_i) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/gemspec/bump.rb', line 7 def data @data end |
Instance Method Details
#==(other) ⇒ Object
16 17 18 |
# File 'lib/gemspec/bump.rb', line 16 def ==(other) data == other.data end |
#apply(diff) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gemspec/bump.rb', line 24 def apply(diff) my_data_r = data.reverse diff_data_r = diff.data.reverse result = my_data_r.zip(diff_data_r).map do |first, second| first = if second =~ /^[+-]/ first + second.to_i else (second and second.to_i) or first end first end.reverse Version.new(result) end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/gemspec/bump.rb', line 20 def to_s @data.join(".") end |