Class: MRuby::Gem::Version

Inherits:
Object show all
Includes:
Comparable, Enumerable
Defined in:
ext/enterprise_script_service/mruby/lib/mruby/gem.rb

Overview

Specification

Constant Summary

Constants included from Enumerable

Enumerable::NONE

Instance Method Summary collapse

Methods included from Enumerable

#+, #all?, #any?, #chain, #collect, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_slice, #each_with_index, #each_with_object, #entries, #find_all, #find_index, #first, #flat_map, #grep, #group_by, #hash, #include?, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #sort, #sort_by, #take, #take_while, #to_h, to_h, #uniq, #zip

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?, #clamp

Constructor Details

#initialize(str) ⇒ Version

Returns a new instance of Version.



285
286
287
288
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 285

def initialize(str)
  @str = str
  @ary = @str.split('.').map(&:to_i)
end

Instance Method Details

#<=>(other) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 250

def <=>(other)
  ret = 0
  own = to_enum

  other.each do |oth|
    begin
      ret = own.next <=> oth
    rescue StopIteration
      ret = 0 <=> oth
    end

    break unless ret == 0
  end

  ret
end

#[](index) ⇒ Object



291
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 291

def [](index); @ary[index]; end

#[]=(index, value) ⇒ Object



292
293
294
295
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 292

def []=(index, value)
  @ary[index] = value
  @str = @ary.join('.')
end

#each(&block) ⇒ Object



290
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 290

def each(&block); @ary.each(&block); end

#skip_minorObject



278
279
280
281
282
283
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 278

def skip_minor
  a = @ary.dup
  a.slice!(-1)
  a[-1] = a[-1].succ
  a
end

#slice!(index) ⇒ Object



296
297
298
299
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 296

def slice!(index)
  @ary.slice!(index)
  @str = @ary.join('.')
end

#twiddle_wakka_ok?(other) ⇒ Boolean

~> compare algorithm

Example:

~> 2.2   means >= 2.2.0 and < 3.0.0
~> 2.2.0 means >= 2.2.0 and < 2.3.0

Returns:

  • (Boolean)


272
273
274
275
276
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 272

def twiddle_wakka_ok?(other)
  gr_or_eql = (self <=> other) >= 0
  still_minor = (self <=> other.skip_minor) < 0
  gr_or_eql and still_minor
end