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.



8
9
10
11
12
# File 'lib/geminabox/gem_version.rb', line 8

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#platformObject

Returns the value of attribute platform.



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

def platform
  @platform
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



31
32
33
34
# File 'lib/geminabox/gem_version.rb', line 31

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

#gemfile_nameObject



36
37
38
39
# File 'lib/geminabox/gem_version.rb', line 36

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

#ruby?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/geminabox/gem_version.rb', line 14

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

#versionObject



18
19
20
# File 'lib/geminabox/gem_version.rb', line 18

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