Class: Eso::ConfigurationAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/eso/configuration/configuration.rb

Overview

The ConfigurationAttribute is a property of the Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, value_class, value) ⇒ ConfigurationAttribute

Returns a new instance of ConfigurationAttribute.



78
79
80
81
82
# File 'lib/eso/configuration/configuration.rb', line 78

def initialize(property, value_class, value)
  @property = property
  @value_class = value_class
  @value = value
end

Instance Attribute Details

#propertyObject

Returns the value of attribute property.



76
77
78
# File 'lib/eso/configuration/configuration.rb', line 76

def property
  @property
end

#valueObject

Returns the value of attribute value.



76
77
78
# File 'lib/eso/configuration/configuration.rb', line 76

def value
  @value
end

#value_classObject

Returns the value of attribute value_class.



76
77
78
# File 'lib/eso/configuration/configuration.rb', line 76

def value_class
  @value_class
end

Class Method Details

.load(array) ⇒ ConfigurationAttribute

Load a ConfigurationAttribute object from an Array

Parameters:

  • array (Array)

    The Array containing the ConfigurationAttribute object

Returns:



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/eso/configuration/configuration.rb', line 112

def self.load(array)
  property = array.first
  value_class = array.last['valueClass']
  value =
      if value_class == Eso::Values::ARRAY
        array.last['items'].map{|item| item['value']}
      else
        array.last['value']
      end
  self.new(property, value_class, value)
end

Instance Method Details

#to_hashHash

Convert the ConfigurationAttribute to a Hash

Returns:

  • (Hash)

    A Hash representation of the ConfigurationAttribute



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/eso/configuration/configuration.rb', line 94

def to_hash
  prop = @property.to_sym
  hash = {prop => {}}
  hash[prop]['valueClass'] = @value_class
  if @value_class == Eso::Values::ARRAY
    items = []
    @value.each{|v| items<< {'value' => v, 'valueClass' => Eso::Values::STRING}}
    hash[prop]['items'] = items
  else
    hash[prop]['value'] = @value
  end
  hash
end

#to_jsonString

Convert the ConfigurationAttribute to a JSON string for sending to Nexpose

Returns:

  • (String)

    A JSON String representation of the ConfigurationAttribute



87
88
89
# File 'lib/eso/configuration/configuration.rb', line 87

def to_json
  self.to_hash.to_json
end