Class: BCL::BaseXml

Inherits:
Object
  • Object
show all
Defined in:
lib/bcl/base_xml.rb

Direct Known Subclasses

Component

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_save_path) ⇒ BaseXml

Returns a new instance of BaseXml.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bcl/base_xml.rb', line 34

def initialize(_save_path)
  @name = '' # this is also a unique identifier to the component...
  @description = ''
  @modeler_description = ''

  @provenances = []
  @tags = []
  @attributes = []
  @files = []

  @schema_url = 'schema.xsd'
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



28
29
30
# File 'lib/bcl/base_xml.rb', line 28

def attributes
  @attributes
end

#costsObject

Returns the value of attribute costs.



30
31
32
# File 'lib/bcl/base_xml.rb', line 30

def costs
  @costs
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#filesObject

Returns the value of attribute files.



29
30
31
# File 'lib/bcl/base_xml.rb', line 29

def files
  @files
end

#modeler_descriptionObject

Returns the value of attribute modeler_description.



24
25
26
# File 'lib/bcl/base_xml.rb', line 24

def modeler_description
  @modeler_description
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/bcl/base_xml.rb', line 22

def name
  @name
end

#provenancesObject

Returns the value of attribute provenances.



32
33
34
# File 'lib/bcl/base_xml.rb', line 32

def provenances
  @provenances
end

#tagsObject

Returns the value of attribute tags.



31
32
33
# File 'lib/bcl/base_xml.rb', line 31

def tags
  @tags
end

#uuidObject

Returns the value of attribute uuid.



25
26
27
# File 'lib/bcl/base_xml.rb', line 25

def uuid
  @uuid
end

#vuidObject

Returns the value of attribute vuid.



26
27
28
# File 'lib/bcl/base_xml.rb', line 26

def vuid
  @vuid
end

Instance Method Details

#add_attribute(name, value, units, datatype = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bcl/base_xml.rb', line 71

def add_attribute(name, value, units, datatype = nil)
  attr = AttrStruct.new
  attr.name = name
  attr.value = value

  if !datatype.nil?
    attr.datatype = datatype
  else
    attr.datatype = get_datatype(value)
  end
  attr.units = units

  @attributes << attr
end

#add_file(version_sp, version_id, fqp_file, filename, filetype, usage_type = nil, checksum = nil) ⇒ Object



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

def add_file(version_sp, version_id, fqp_file, filename, filetype, usage_type = nil, checksum = nil)
  fs = FileStruct.new
  fs.version_software_program = version_sp
  fs.version_id = version_id
  fs.fqp_file = fqp_file
  fs.filename = filename
  fs.filetype = filetype
  fs.usage_type = usage_type unless usage_type.nil?
  fs.checksum = checksum unless checksum.nil?

  @files << fs
end

#add_provenance(author, datetime, comment) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/bcl/base_xml.rb', line 55

def add_provenance(author, datetime, comment)
  prov = ProvStruct.new
  prov.author = author
  prov.datetime = datetime
  prov.comment = comment

  @provenances << prov
end

#add_tag(tag_name) ⇒ Object



64
65
66
67
68
69
# File 'lib/bcl/base_xml.rb', line 64

def add_tag(tag_name)
  tag = TagsStruct.new
  tag.descriptor = tag_name

  @tags << tag
end

#generate_uuidObject



47
48
49
# File 'lib/bcl/base_xml.rb', line 47

def generate_uuid
  @uuid = UUID.new.generate
end

#generate_vuidObject



51
52
53
# File 'lib/bcl/base_xml.rb', line 51

def generate_vuid
  @vuid = UUID.new.generate
end

#get_attribute(attribute_name) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/bcl/base_xml.rb', line 109

def get_attribute(attribute_name)
  result = nil
  @attributes.each do |attr|
    if attr.name == attribute_name
      result = attr
    end
  end

  result
end

#get_datatype(input_value) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/bcl/base_xml.rb', line 120

def get_datatype(input_value)
  dt = 'undefined'

  # simple method to test if the input_value is a string, float, or integer.
  # First convert the value back to a string for testing (in case it was passed as a float/integer)
  test = input_value.to_s
  input_value = begin
                  test.match('\.').nil? ? Integer(test) : Float(test)
                rescue StandardError
                  test.to_s
                end

  if input_value.is_a?(Integer) || input_value.is_a?(Integer)
    dt = 'int'
  elsif input_value.is_a?(Float)
    dt = 'float'
  else
    dt = 'string'
  end

  dt
end

#tc(input) ⇒ Object

return the title case of the string



100
101
102
103
104
105
106
107
# File 'lib/bcl/base_xml.rb', line 100

def tc(input)
  val = input.gsub(/\b\w/) { $&.upcase }
  if val.casecmp('energyplus').zero?
    val = 'EnergyPlus'
  end

  val
end