Class: UserData

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/userdata_enums.rb

Class Method Summary collapse

Class Method Details

.boolean_to_string(value) ⇒ Object



36
37
38
39
40
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/userdata_enums.rb', line 36

def self.boolean_to_string(value)
  return value if value.nil? || value.is_a?(Numeric) # For consistency in further comparison


  value.is_a?(TrueClass) || value.is_a?(FalseClass) ? value.to_s : value
end

.compare(one, another) ⇒ Boolean

Compare the two UserData enums are the same or not. Static method.

Parameters:

  • one (String)

    one UserData type enum

  • another (String)

    another UserDataType enum

Returns:

  • (Boolean)

    if the two enums or strings are the same



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/userdata_enums.rb', line 23

def self.compare(one, another)
  return false if one.nil? || another.nil?

  one_value = boolean_to_string(one)
  another_value = boolean_to_string(another)

  if one_value.is_a?(String) && another_value.is_a?(String)
    return one_value.strip.downcase == another_value.strip.downcase
  else
    return one_value == another_value
  end
end

.get_constant_valuesObject

Static method that retrieves the function constant values in a list



3
4
5
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/userdata_enums.rb', line 3

def self.get_constant_values
  return constants.map(&method(:const_get))
end

.matched_any?(user_data) ⇒ Boolean

Static method to check if a user data matches to any of the constant value

Parameters:

  • user_data (String)

    a user data

Returns:

  • (Boolean)

    matched any, else false



11
12
13
14
15
16
17
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/userdata_enums.rb', line 11

def self.matched_any?(user_data)
  userdata_constants = get_constant_values
  userdata_constants.each do |constant|
    return true if compare(user_data, constant)
  end
  return false
end