Module: Versionaire
- Defined in:
- lib/versionaire/conversion.rb,
lib/versionaire/version.rb,
lib/versionaire/identity.rb,
lib/versionaire/errors/base.rb,
lib/versionaire/errors/conversion.rb,
lib/versionaire/errors/invalid_number.rb,
lib/versionaire/errors/negative_number.rb
Overview
The gem namespace.
Defined Under Namespace
Modules: Errors, Identity Classes: Version
Class Method Summary collapse
-
.Version(value) ⇒ Object
Conversion function for casting (strict) a value into a version.
Class Method Details
.Version(value) ⇒ Object
Conversion function for casting (strict) a value into a version. rubocop:disable Style/MethodName rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/versionaire/conversion.rb', line 10 def Version value case value when String fail(Errors::Conversion, Errors::Conversion.) unless value =~ Version.format Version.new Version.arguments(*value.tr("v", "").split(".").map(&:to_i)) when Array fail(Errors::Conversion, Errors::Conversion.) unless (0..3).cover?(value.size) Version.new Version.arguments(*value.fill(0, value.size..2)) when Hash valid = value.keys.all? { |key| Version.keys.include? key } fail(Errors::Conversion, Errors::Conversion.) unless valid Version.new value when Version then value else fail(Errors::Conversion, Errors::Conversion.) end end |