Class: Herve::Ruby::Request
- Inherits:
-
Data
- Object
- Data
- Herve::Ruby::Request
- Defined in:
- lib/herve/ruby/request.rb,
lib/herve/ruby/request.rb
Constant Summary collapse
- VERSION_FIELDS =
%i[major minor patch tiny prerelease].freeze
- ALPHA_RE =
/^[[:alpha:]]/
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#prerelease ⇒ Object
readonly
Returns the value of attribute prerelease.
-
#tiny ⇒ Object
readonly
Returns the value of attribute tiny.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #find_match_in(rubies) ⇒ Object
- #satisfied_by(ruby) ⇒ Object
-
#to_s ⇒ Object
rubocop:disable Metrics/AbcSize.
- #version_number ⇒ Object
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine
8 9 10 |
# File 'lib/herve/ruby/request.rb', line 8 def engine @engine end |
#major ⇒ Object (readonly)
Returns the value of attribute major
8 9 10 |
# File 'lib/herve/ruby/request.rb', line 8 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor
8 9 10 |
# File 'lib/herve/ruby/request.rb', line 8 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch
8 9 10 |
# File 'lib/herve/ruby/request.rb', line 8 def patch @patch end |
#prerelease ⇒ Object (readonly)
Returns the value of attribute prerelease
8 9 10 |
# File 'lib/herve/ruby/request.rb', line 8 def prerelease @prerelease end |
#tiny ⇒ Object (readonly)
Returns the value of attribute tiny
8 9 10 |
# File 'lib/herve/ruby/request.rb', line 8 def tiny @tiny end |
Class Method Details
.dissect_version(version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/herve/ruby/request.rb', line 31 def dissect_version(version) return [nil] * 4 if version.nil? number = nil pre = nil if version[0] =~ ALPHA_RE raise RequestError, "invalid version" unless version == "dev" pre = version else number, pre = version.split("-", 2) end numbers = if number number.split(".").map(&:to_i) else [] end raise RequestError, "too many numbers in version #{version}" if numbers.size > 4 numbers.concat([nil] * (4 - numbers.size)) numbers << pre end |
.parse(str) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/herve/ruby/request.rb', line 17 def parse(str) raise RequestError, "invalid string" if str.empty? str = str.strip engine, version = if str[0] =~ ALPHA_RE str.split("-", 2) else ["ruby", str] end major, minor, patch, tiny, pre = dissect_version(version) new(Engine.new(engine), major, minor, patch, tiny, pre) end |
Instance Method Details
#<=>(other) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/herve/ruby/request.rb', line 87 def <=>(other) res = engine <=> other.engine return res if res != 0 return 1 if !major.nil? && other.major.nil? return 1 if !major.nil? && (major > other.major) return -1 if !major.nil? && (major < other.major) return 1 if !minor.nil? && other.minor.nil? return 1 if !minor.nil? && (minor > other.minor) return -1 if !minor.nil? && (minor < other.minor) return 1 if !patch.nil? && other.patch.nil? return 1 if !patch.nil? && (patch > other.patch) return -1 if !patch.nil? && (patch < other.patch) return 1 if !tiny.nil? && other.tiny.nil? return 1 if !tiny.nil? && (tiny > other.tiny) return -1 if !tiny.nil? && (tiny < other.tiny) return 1 if prerelease.nil? && !other.prerelease.nil? return -1 if !prerelease.nil? && other.prerelease.nil? return 1 if !prerelease.nil? && (prerelease > other.prerelease) return -1 if !prerelease.nil? && (prerelease < other.prerelease) 0 end |
#find_match_in(rubies) ⇒ Object
73 74 75 |
# File 'lib/herve/ruby/request.rb', line 73 def find_match_in(rubies) rubies.find { |ruby| satisfied_by(ruby) } end |
#satisfied_by(ruby) ⇒ Object
77 78 79 80 81 |
# File 'lib/herve/ruby/request.rb', line 77 def satisfied_by(ruby) other = ruby.version (engine == other.engine) && check_fields(other, VERSION_FIELDS) end |
#to_s ⇒ Object
rubocop:disable Metrics/AbcSize
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/herve/ruby/request.rb', line 56 def to_s # rubocop:disable Metrics/AbcSize str = engine.to_s unless major.nil? str << "-#{major}" unless minor.nil? str << ".#{minor}" unless patch.nil? str << ".#{patch}" str << ".#{tiny}" unless tiny.nil? end end end str << "-#{prerelease}" if prerelease str end |
#version_number ⇒ Object
83 84 85 |
# File 'lib/herve/ruby/request.rb', line 83 def version_number VERSION_FIELDS.map { |m| send(m) }.compact.join(".") end |