Class: OpenStudioAmis

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

Overview

Class for managing the AMI ids based on the openstudio version and the openstudio-server version

Constant Summary collapse

VALID_OPTIONS =
[
  :openstudio_version, :openstudio_server_version, :host, :url
]

Instance Method Summary collapse

Constructor Details

#initialize(version = 1, options = {}) ⇒ OpenStudioAmis

Returns a new instance of OpenStudioAmis.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/openstudio/lib/ami_list.rb', line 28

def initialize(version = 1, options = {})
  invalid_options = options.keys - VALID_OPTIONS
  if invalid_options.any?
    fail ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
  end

  # merge in some defaults
  defaults = {
    openstudio_version: 'default',
    openstudio_server_version: 'default',
    host: 'developer.nrel.gov',
    url: '/downloads/buildings/openstudio/api'
  }
  @version = version
  @options = defaults.merge(options)
end

Instance Method Details

#get_amisObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/openstudio/lib/ami_list.rb', line 57

def get_amis
  amis = nil
  command = "get_ami_version_#{@version}"
  if OpenStudioAmis.method_defined?(command)
    amis = send(command)
  else
    fail "Unknown api version command #{command}"
  end

  fail "Could not find any amis for #{@version}" if amis.nil?

  amis
end

#listObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/openstudio/lib/ami_list.rb', line 45

def list
  json = nil
  command = "list_amis_version_#{@version}"
  if OpenStudioAmis.method_defined?(command)
    json = send(command)
  else
    fail "Unknown api version command #{command}"
  end

  json
end