Class: Typesmith::IndexedProperty
- Inherits:
-
BaseProperty
- Object
- BaseProperty
- Typesmith::IndexedProperty
- Defined in:
- lib/typesmith/indexed_property.rb
Constant Summary
Constants inherited from BaseProperty
Instance Attribute Summary collapse
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
-
#value_type ⇒ Object
readonly
Returns the value of attribute value_type.
Attributes inherited from BaseProperty
Instance Method Summary collapse
-
#initialize(name, key_type, value_type, optional: false) ⇒ IndexedProperty
constructor
A new instance of IndexedProperty.
- #process_value(value) ⇒ Object
- #to_typescript ⇒ Object
Constructor Details
#initialize(name, key_type, value_type, optional: false) ⇒ IndexedProperty
Returns a new instance of IndexedProperty.
7 8 9 10 11 12 13 |
# File 'lib/typesmith/indexed_property.rb', line 7 def initialize(name, key_type, value_type, optional: false) super(name, optional: optional) @key_type = key_type @value_type = value_type self.class.validate_type(key_type) self.class.validate_type(value_type) end |
Instance Attribute Details
#key_type ⇒ Object (readonly)
Returns the value of attribute key_type.
5 6 7 |
# File 'lib/typesmith/indexed_property.rb', line 5 def key_type @key_type end |
#value_type ⇒ Object (readonly)
Returns the value of attribute value_type.
5 6 7 |
# File 'lib/typesmith/indexed_property.rb', line 5 def value_type @value_type end |
Instance Method Details
#process_value(value) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/typesmith/indexed_property.rb', line 19 def process_value(value) value.transform_values do |v| if value_type.is_a?(Array) v.map { |item| SimpleProperty.new(nil, value_type.first).process_value(item) } else SimpleProperty.new(nil, value_type).process_value(v) end end end |
#to_typescript ⇒ Object
15 16 17 |
# File 'lib/typesmith/indexed_property.rb', line 15 def to_typescript "#{camelized_name}#{optional_suffix}: { [key: #{get_type_string(key_type)}]: #{get_type_string(value_type)} };" end |