Class: Bumpversion::BumpString

Inherits:
Object
  • Object
show all
Defined in:
lib/bumpversion/bump_string.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BumpString

Returns a new instance of BumpString.



3
4
5
# File 'lib/bumpversion/bump_string.rb', line 3

def initialize(options)
  @options = options
end

Instance Method Details

#bumpObject



40
41
42
43
44
45
46
47
# File 'lib/bumpversion/bump_string.rb', line 40

def bump
  unless @options[:new_version]
    matched_version = update_version(matched)
    new_version_hash = matched_version.map { |_key, value| value.to_s }
    @options[:new_version] = new_version_hash.join('.')
  end
  @options
end

#dictionaryObject



7
8
9
# File 'lib/bumpversion/bump_string.rb', line 7

def dictionary
  { major: 1, minor: 2, patch: 3 }
end

#key_partObject



11
12
13
# File 'lib/bumpversion/bump_string.rb', line 11

def key_part
  @options[:part].to_sym
end

#matchedObject



19
20
21
22
23
24
# File 'lib/bumpversion/bump_string.rb', line 19

def matched
  match = pattern.match(@options[:current_version])
  matched = {}
  dictionary.each { |part, number| matched[part] = match[number].to_i }
  matched
end

#patternObject



15
16
17
# File 'lib/bumpversion/bump_string.rb', line 15

def pattern
  /([0-9]+)\.([0-9]+)\.([0-9]+)/
end

#update_version(matched_version) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bumpversion/bump_string.rb', line 26

def update_version(matched_version)
  bumped = false
  matched_version.each do | part, number |
    matched_version[part] = 0 if bumped

    if part == key_part
      matched_version[part] += 1
      bumped = true
    end
  end

  matched_version
end