Class: Gemi::Gem
- Inherits:
-
Object
- Object
- Gemi::Gem
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #has?(key) ⇒ Boolean
-
#initialize(gem_hash) ⇒ Gem
constructor
A new instance of Gem.
- #native? ⇒ Boolean
- #to_command ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/gem.rb', line 8 def name @name end |
#version ⇒ Object (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
29 30 31 |
# File 'lib/gem.rb', line 29 def has?(key) @gem_hash.keys.include? key end |
#native? ⇒ Boolean
25 26 27 |
# File 'lib/gem.rb', line 25 def native? @gem_hash['native'] == 1 end |
#to_command ⇒ Object
33 34 35 |
# File 'lib/gem.rb', line 33 def to_command "gem install #{@name} --version #{@version}" end |