Class: Kali::Type::List
- Inherits:
-
Kali::Type
- Object
- Kali::Type
- Kali::Type::List
- Defined in:
- lib/kali/type/list.rb
Overview
Meta type (not explicitly defined in the RFC as a property type) to parse and serialize lists of other values. Lists are strongly typed, with elements of only one type occurring inside a list.
Instance Method Summary collapse
- #decode!(string) ⇒ Object
- #encode!(object) ⇒ Object
-
#initialize(subtype, restriction = nil) ⇒ List
constructor
A new instance of List.
Methods inherited from Kali::Type
Constructor Details
#initialize(subtype, restriction = nil) ⇒ List
Returns a new instance of List.
8 9 10 11 |
# File 'lib/kali/type/list.rb', line 8 def initialize(subtype, restriction = nil) super(restriction) @subtype = subtype end |
Instance Method Details
#decode!(string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kali/type/list.rb', line 17 def decode!(string) tentative_parts = string.split(",") parts = [] in_group = false group_size = 1 tentative_parts.each.with_index do |part, index| if part[-1] == "\\" group_size += 1 in_group = true elsif in_group parts << tentative_parts[index - group_size + 1, group_size].join(",") group_size = 1 in_group = false else parts << part end end parts.map { |part| @subtype.decode(part) } end |
#encode!(object) ⇒ Object
13 14 15 |
# File 'lib/kali/type/list.rb', line 13 def encode!(object) object.map { |el| @subtype.encode(el) }.join(",") end |