Class: SemverDialects::Semver2::VersionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/semver_dialects/semver2.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ VersionParser

Returns a new instance of VersionParser.



105
106
107
108
# File 'lib/semver_dialects/semver2.rb', line 105

def initialize(input)
  @input = input
  @scanner = StringScanner.new(input)
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



103
104
105
# File 'lib/semver_dialects/semver2.rb', line 103

def input
  @input
end

Class Method Details

.parse(input) ⇒ Object



99
100
101
# File 'lib/semver_dialects/semver2.rb', line 99

def self.parse(input)
  new(input).parse
end

Instance Method Details

#parseObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/semver_dialects/semver2.rb', line 110

def parse
  tokens = []
  prerelease_tag = nil

  # skip ignore leading v if any
  scanner.skip('v')

  until scanner.eos?
    if (s = scanner.scan(/\d+/))
      tokens << s.to_i
    elsif (s = scanner.scan(/\.x\z/i))
      tokens << ANY_NUMBER
    elsif (s = scanner.scan('.'))
      # continue
    elsif (s = scanner.scan('-'))
      prerelease_tag = parse_prerelease_tag
    elsif (s = scanner.scan(/\+.*/))
      # continue
    else
      raise IncompleteScanError, scanner.rest
    end
  end

  Version.new(tokens, prerelease_tag: prerelease_tag)
end