Class: Bake::Types::Array

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/bake/types/array.rb

Instance Method Summary collapse

Methods included from Type

#|

Constructor Details

#initialize(item_type) ⇒ Array

Returns a new instance of Array.



30
31
32
# File 'lib/bake/types/array.rb', line 30

def initialize(item_type)
	@item_type = item_type
end

Instance Method Details

#composite?Boolean

Returns:



34
35
36
# File 'lib/bake/types/array.rb', line 34

def composite?
	true
end

#map(values) ⇒ Object



38
39
40
# File 'lib/bake/types/array.rb', line 38

def map(values)
	values.map{|value| @item_type.parse(value)}
end

#parse(input) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/bake/types/array.rb', line 42

def parse(input)
	case input
	when ::String
		return input.split(',').map{|value| @item_type.parse(value)}
	when ::Array
		return input.map{|value| @item_type.parse(value)}
	else
		raise ArgumentError, "Cannot coerce #{input.inspect} into array!"
	end
end

#to_sObject



53
54
55
# File 'lib/bake/types/array.rb', line 53

def to_s
	"an Array of #{@item_type}"
end