Module: UbuntuAmis

Defined in:
lib/ubuntu_amis.rb,
lib/ubuntu_amis/version.rb

Constant Summary collapse

URL =
"http://cloud-images.ubuntu.com/locator/ec2/releasesTable"
VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.fix_string(data) ⇒ Object



23
24
25
# File 'lib/ubuntu_amis.rb', line 23

def self.fix_string(data)
  data.reverse.sub(',','').reverse
end

.fix_table(table) ⇒ Object



27
28
29
30
31
32
# File 'lib/ubuntu_amis.rb', line 27

def self.fix_table(table)
  table.each_with_index{|row,index|
    table[index][6] = row[6][/(ami-[\da-f]{8})/,1]
  }
  table
end

.get(uri) ⇒ Object



19
20
21
# File 'lib/ubuntu_amis.rb', line 19

def self.get(uri)
  Net::HTTP.get_response(uri).body
end

.parse(json) ⇒ Object



34
35
36
# File 'lib/ubuntu_amis.rb', line 34

def self.parse(json)
  YAML.load(json)
end

.tableObject



9
10
11
# File 'lib/ubuntu_amis.rb', line 9

def self.table
  fix_table(parse(fix_string(get(uri)))["aaData"])
end

.uriObject



13
14
15
16
17
# File 'lib/ubuntu_amis.rb', line 13

def self.uri
  URI(URL).tap { |uri|
    uri.query = Time.now.to_i.to_s
  }
end