Class: NRSER::Types::TupleType
- Defined in:
- lib/nrser/types/tuples.rb
Overview
Tuple type - array of fixed length and types (though those could be ANY).
Constant Summary
Constants inherited from ArrayType
Instance Attribute Summary
Attributes inherited from ArrayType
Attributes inherited from IsA
Instance Method Summary collapse
- #default_name ⇒ Object
-
#has_from_s? ⇒ Boolean
‘true` if this type can load values from a string, which is true if all it’s types can load values from strings.
-
#initialize(*types, **options) ⇒ TupleType
constructor
Instantiate a new ‘TupleType`.
-
#items_from_strings(strings) ⇒ Array
Load each value in an array of strings split out by ArrayType#from_s by passing each value to ‘#from_s` in the type of the corresponding index.
- #test(value) ⇒ return_type
Methods inherited from ArrayType
Methods inherited from IsA
Methods inherited from Type
#check, #from_data, #from_s, #has_from_data?, #has_to_data?, #name, #respond_to?, short_name, #to_data, #to_s
Constructor Details
Instance Method Details
#default_name ⇒ Object
53 54 55 |
# File 'lib/nrser/types/tuples.rb', line 53 def default_name '[' + @types.map( &:name ).join( ', ' ) + ']' end |
#has_from_s? ⇒ Boolean
Returns ‘true` if this type can load values from a string, which is true if all it’s types can load values from strings.
87 88 89 |
# File 'lib/nrser/types/tuples.rb', line 87 def has_from_s? @types.all? &:has_from_s? end |
#items_from_strings(strings) ⇒ Array
Load each value in an array of strings split out by ArrayType#from_s by passing each value to ‘#from_s` in the type of the corresponding index.
100 101 102 103 104 |
# File 'lib/nrser/types/tuples.rb', line 100 def items_from_strings strings @types.each_with_index.map { |type, index| type.from_s strings[index] } end |
#test(value) ⇒ return_type
Document test method.
Returns @todo Document return value.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/nrser/types/tuples.rb', line 69 def test value # Test the super class first return false unless super( value ) # If it's not the right length then it doesn't pass return false unless value.length == @types.length # Test each item type @types.each_with_index.all? { |type, index| type.test value[index] } end |