Class: Geminabox::GemVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/geminabox/gem_version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, number, platform) ⇒ GemVersion

Returns a new instance of GemVersion.



6
7
8
9
10
# File 'lib/geminabox/gem_version.rb', line 6

def initialize(name, number, platform)
  @name = name
  @number = number
  @platform = platform
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/geminabox/gem_version.rb', line 4

def name
  @name
end

#numberObject

Returns the value of attribute number.



4
5
6
# File 'lib/geminabox/gem_version.rb', line 4

def number
  @number
end

#platformObject

Returns the value of attribute platform.



4
5
6
# File 'lib/geminabox/gem_version.rb', line 4

def platform
  @platform
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/geminabox/gem_version.rb', line 20

def <=>(other)
  sort = other.name <=> name
  sort = version <=>  other.version       if sort.zero?
  sort = (other.ruby? && !ruby?) ? 1 : -1 if sort.zero? && ruby? != other.ruby?
  sort = other.platform <=> platform      if sort.zero?

  sort
end

#==(other) ⇒ Object



29
30
31
32
# File 'lib/geminabox/gem_version.rb', line 29

def ==(other)
  return false unless other.class == self.class
  [name, number, platform] == [other.name, other.number, other.platform]
end

#gemfile_nameObject



34
35
36
37
# File 'lib/geminabox/gem_version.rb', line 34

def gemfile_name
  included_platform = ruby? ? nil : platform
  [name, number, included_platform].compact.join('-')
end

#ruby?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/geminabox/gem_version.rb', line 12

def ruby?
  !!(platform =~ /ruby/i)
end

#versionObject



16
17
18
# File 'lib/geminabox/gem_version.rb', line 16

def version
  Gem::Version.create(number)
end