Class: QuickMug::Image

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, key) ⇒ Image

Returns a new instance of Image.



5
6
7
8
# File 'lib/quickmug/image.rb', line 5

def initialize(id, key)
  @id = id
  @key = key
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/quickmug/image.rb', line 3

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/quickmug/image.rb', line 3

def key
  @key
end

Class Method Details

.fromApi(data) ⇒ Object



32
33
34
# File 'lib/quickmug/image.rb', line 32

def self.fromApi(data)
  Image.new(data['id'], data['Key'])
end

.fromArgs(args) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
# File 'lib/quickmug/image.rb', line 36

def self.fromArgs(args)
  raise ArgumentError.new('You must specify an image ID and KEY') if args.size < 2
  Image.new(args[0],args[1])
end

Instance Method Details

#apiHashObject



10
11
12
# File 'lib/quickmug/image.rb', line 10

def apiHash
  {:ImageID => @id, :ImageKey => @key}
end

#infoObject



14
15
16
# File 'lib/quickmug/image.rb', line 14

def info
  @info ||= QuickMug.client.images.getInfo(apiHash)
end

#renderObject



22
23
24
25
26
27
28
29
30
# File 'lib/quickmug/image.rb', line 22

def render
  output = QuickMug.config['format']

  info.each do |key, value|
    output = output.gsub("[#{key}]", value.to_s)
  end

  output
end

#to_sObject



18
19
20
# File 'lib/quickmug/image.rb', line 18

def to_s
  render
end