Class: BCDD::Data::Properties
- Inherits:
-
Object
- Object
- BCDD::Data::Properties
- Defined in:
- lib/bcdd/ext/data.rb
Instance Attribute Summary collapse
-
#contract ⇒ Object
readonly
Returns the value of attribute contract.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
Instance Method Summary collapse
- #attribute(name, **options) ⇒ Object
- #contract? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize ⇒ Properties
constructor
A new instance of Properties.
- #map(input) ⇒ Object
Constructor Details
#initialize ⇒ Properties
Returns a new instance of Properties.
29 30 31 32 |
# File 'lib/bcdd/ext/data.rb', line 29 def initialize @spec = {} @contract = false end |
Instance Attribute Details
#contract ⇒ Object (readonly)
Returns the value of attribute contract.
27 28 29 |
# File 'lib/bcdd/ext/data.rb', line 27 def contract @contract end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
27 28 29 |
# File 'lib/bcdd/ext/data.rb', line 27 def spec @spec end |
Instance Method Details
#attribute(name, **options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bcdd/ext/data.rb', line 34 def attribute(name, **) name.is_a?(Symbol) or raise ArgumentError, "#{name.inspect} must be a Symbol" value_option = [:value] spec[name] = if value_option (value_option.is_a?(Value::Object) ? value_option : Value[value_option])::Properties else Value::Properties.new().freeze end end |
#contract? ⇒ Boolean
55 56 57 |
# File 'lib/bcdd/ext/data.rb', line 55 def contract? contract end |
#freeze ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/bcdd/ext/data.rb', line 47 def freeze @contract = spec.any? { |_, properties| properties.contract? } spec.freeze super end |
#map(input) ⇒ Object
59 60 61 62 63 |
# File 'lib/bcdd/ext/data.rb', line 59 def map(input) spec.each_with_object({}) do |(name, properties), output| output[name] = properties.map(input[name]) end end |