Class: Bake::Types::Array
- Inherits:
-
Object
- Object
- Bake::Types::Array
- Includes:
- Type
- Defined in:
- lib/bake/types/array.rb
Instance Method Summary collapse
- #composite? ⇒ Boolean
-
#initialize(item_type) ⇒ Array
constructor
A new instance of Array.
- #map(values) ⇒ Object
- #parse(input) ⇒ Object
- #to_s ⇒ Object
Methods included from Type
Constructor Details
#initialize(item_type) ⇒ Array
Returns a new instance of Array.
13 14 15 |
# File 'lib/bake/types/array.rb', line 13 def initialize(item_type) @item_type = item_type end |
Instance Method Details
#map(values) ⇒ Object
21 22 23 |
# File 'lib/bake/types/array.rb', line 21 def map(values) values.map{|value| @item_type.parse(value)} end |
#parse(input) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bake/types/array.rb', line 25 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_s ⇒ Object
36 37 38 |
# File 'lib/bake/types/array.rb', line 36 def to_s "an Array of #{@item_type}" end |