Class: Bake::Type::Hash

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/bake/type/hash.rb

Instance Method Summary collapse

Methods included from Type

#|

Constructor Details

#initialize(key_type, value_type) ⇒ Hash

Returns a new instance of Hash.



13
14
15
16
# File 'lib/bake/type/hash.rb', line 13

def initialize(key_type, value_type)
  @key_type = key_type
  @value_type = value_type
end

Instance Method Details

#composite?Boolean

Returns:



18
19
20
# File 'lib/bake/type/hash.rb', line 18

def composite?
  true
end

#parse(input) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bake/type/hash.rb', line 22

def parse(input)
  hash = {}
  
  input.split(",").each do |pair|
    key, value = pair.split(":", 2)
    
    key = @key_type.parse(key)
    value = @value_type.parse(value)
      
    hash[key] = value
  end
  
  return hash
end