Class: Oscal::Value
- Includes:
- Serializer
- Defined in:
- lib/oscal/value.rb
Constant Summary collapse
- KEY =
i(val)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Value
constructor
A new instance of Value.
Methods included from Serializer
included, #to_h, #to_json, #to_xml, #to_yaml
Methods inherited from BaseClass
Constructor Details
#initialize(options = {}) ⇒ Value
Returns a new instance of Value.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/oscal/value.rb', line 21 def initialize( = {}) unless .is_a? Hash = { "val" => } end .each_pair.each do |key, val| key_name = key.gsub("-", "_") unless KEY.include?(key_name.to_sym) raise UnknownAttributeError.new("Unknown key `#{key}` in Value") end self.send("#{key_name}=", val) end end |
Class Method Details
.wrap(obj) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/oscal/value.rb', line 12 def self.wrap(obj) return obj if obj.is_a? Value return Value.new(obj) unless obj.is_a? Array obj.map do |x| Value.wrap(x) end end |