Class: Honeybee::Extension

Inherits:
OpenStudio::Extension::Extension
  • Object
show all
Defined in:
lib/honeybee/extension.rb

Constant Summary collapse

@@schema =
nil
@@standards =
nil

Instance Method Summary collapse

Constructor Details

#initializeExtension

Override parent class



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/honeybee/extension.rb', line 43

def initialize
  super

  # Note that the root_dir is only meaningful when the gem is in a github repository
  # When installed as a Ruby gem, the highest directory within the gem is the lib_dir
  @root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
  @lib_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..'))

  @instance_lock = Mutex.new
  @@schema ||= schema
  @@standards ||= standards
end

Instance Method Details

#doc_templates_dirObject

Doc templates are common files like copyright files which are used to update measures Doc templates will only be applied when the gem is a part of a repository Return the absolute path of the doc templates dir or nil if there is none



72
73
74
# File 'lib/honeybee/extension.rb', line 72

def doc_templates_dir
  File.absolute_path(File.join(@root_dir, 'doc_templates'))
end

#files_dirObject

Relevant files such as the openapi JSON schema files for the honeybee model. Return the absolute path of the files or nil if there is none. Used when configuring OSWs



65
66
67
# File 'lib/honeybee/extension.rb', line 65

def files_dir
  File.absolute_path(File.join(@lib_dir, 'files'))
end

#measures_dirObject

Return the absolute path of the measures or nil if there is none. Can be used when configuring OSWs



58
59
60
# File 'lib/honeybee/extension.rb', line 58

def measures_dir
  File.absolute_path(File.join(@lib_dir, 'measures'))
end

#schemaObject

return the model schema



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/honeybee/extension.rb', line 87

def schema
  @instance_lock.synchronize do
    if @@schema.nil?
      File.open(schema_file, 'r') do |f|
        @@schema = JSON.parse(f.read, symbolize_names: true)
      end
    end
  end

  @@schema
end

#schema_fileObject

return path to the model schema file



77
78
79
# File 'lib/honeybee/extension.rb', line 77

def schema_file
  File.join(@lib_dir, 'honeybee', '_defaults', 'model.json')
end

#standardsObject

return the JSON of default standards



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/honeybee/extension.rb', line 100

def standards
  @instance_lock.synchronize do
    if @@standards.nil?
      File.open(standards_file, 'r') do |f|
        @@standards = JSON.parse(f.read, symbolize_names: true)
      end
    end
  end

  @@standards
end

#standards_fileObject

return path to the model standards file



82
83
84
# File 'lib/honeybee/extension.rb', line 82

def standards_file
  File.join(@lib_dir, 'honeybee', '_defaults', 'energy_default.json')
end