Class: NRSER::Types::Tuple
- Defined in:
- lib/nrser/types/tuples.rb
Overview
Constant Summary
Constants inherited from ArrayType
Instance Attribute Summary collapse
-
#types ⇒ Array<Type>
readonly
The types of each of the tuple indexes.
Attributes inherited from IsA
Instance Method Summary collapse
- #default_name ⇒ Object
- #default_symbolic ⇒ Object
- #explain ⇒ String
-
#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) ⇒ Tuple
constructor
Instantiate a new ‘Tuple`.
-
#items_from_strings(strings) ⇒ Array
Load each value in an array of strings split out by NRSER::Types::Type#from_s by passing each value to ‘#from_s` in the type of the corresponding index.
-
#test?(value) ⇒ Boolean
Test value for membership.
Methods inherited from ArrayType
Methods inherited from IsA
#==, #custom_from_data, #has_from_data?, #init_from_data?
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_data?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #symbolic, #test, #to_data, #to_proc, #to_s, #union, #xor
Constructor Details
Instance Attribute Details
Instance Method Details
#default_name ⇒ Object
62 63 64 |
# File 'lib/nrser/types/tuples.rb', line 62 def default_name 'Array<(' + types.map( &:name ).join( ', ' ) + ')>' end |
#default_symbolic ⇒ Object
67 68 69 |
# File 'lib/nrser/types/tuples.rb', line 67 def default_symbolic '[' + types.map( &:symbolic ).join( ', ' ) + ']' end |
#explain ⇒ String
Returns See NRSER::Types::Type#explain.
75 76 77 |
# File 'lib/nrser/types/tuples.rb', line 75 def explain 'Array<(' + types.map( &:explain ).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.
107 108 109 |
# File 'lib/nrser/types/tuples.rb', line 107 def has_from_s? @from_s || types.all?( &:has_from_s? ) end |
#items_from_strings(strings) ⇒ Array
Load each value in an array of strings split out by NRSER::Types::Type#from_s by passing each value to ‘#from_s` in the type of the corresponding index.
120 121 122 123 124 |
# File 'lib/nrser/types/tuples.rb', line 120 def items_from_strings strings types.each_with_index.map { |type, index| type.from_s strings[index] } end |
#test?(value) ⇒ Boolean
Test value for membership.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nrser/types/tuples.rb', line 89 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 |