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, #filter_map, #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, #tally, #to_h, #uniq, #zip

Methods included from Comparable

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

Constructor Details

#initialize(str) ⇒ Version

Returns a new instance of Version.



333
334
335
336
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 333

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

Instance Method Details

#<=>(other) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 296

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



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

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

#[]=(index, value) ⇒ Object



340
341
342
343
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 340

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

#each(&block) ⇒ Object



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

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

#skip_major_or_minorObject



325
326
327
328
329
330
331
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 325

def skip_major_or_minor
  a = @ary.dup
  a << 0 if a.size == 1 # ~> 2 can also be represented as ~> 2.0
  a.slice!(-1)
  a[-1] = a[-1].succ
  a
end

#slice!(index) ⇒ Object



344
345
346
347
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 344

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

#twiddle_wakka_ok?(other) ⇒ Boolean

~> compare algorithm

Example:

~> 2     means >= 2.0.0 and < 3.0.0
~> 2.2   means >= 2.2.0 and < 3.0.0
~> 2.2.2 means >= 2.2.2 and < 2.3.0

Returns:

  • (Boolean)


319
320
321
322
323
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 319

def twiddle_wakka_ok?(other)
  gr_or_eql = (self <=> other) >= 0
  still_major_or_minor = (self <=> other.skip_major_or_minor) < 0
  gr_or_eql and still_major_or_minor
end