Class: Gemi::Gem

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

Constant Summary collapse

ERR_NOT_A_HASH =
'Failed to initialize hash not given?'
ERR_MISSING_KEY =
'Failed to initialize %s not given?'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_hash) ⇒ Gem

Returns a new instance of Gem.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gem.rb', line 10

def initialize(gem_hash)
  unless gem_hash.is_a? Hash
    raise InvalidGemHashError.new(ERR_NOT_A_HASH)
  end
  @gem_hash = gem_hash
  ['name', 'version', 'native'].each do |key|
    unless has? key
      raise InvalidGemHashError.new(ERR_MISSING_KEY % key)
    end
  end
  @name = @gem_hash['name']
  @version = @gem_hash['version']
  @native = @gem_hash['native']
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/gem.rb', line 8

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/gem.rb', line 8

def version
  @version
end

Instance Method Details

#has?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gem.rb', line 29

def has?(key)
  @gem_hash.keys.include? key
end

#native?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/gem.rb', line 25

def native?
  @gem_hash['native'] == 1
end

#to_commandObject



33
34
35
# File 'lib/gem.rb', line 33

def to_command
  "gem install #{@name} --version #{@version}"
end