Class: NRSER::Types::Shape
Instance Attribute Summary collapse
-
#pairs ⇒ Hash
readonly
TODO document ‘pairs` attribute.
Instance Method Summary collapse
- #custom_from_data(data) ⇒ Object
- #explain ⇒ Object
- #has_from_data? ⇒ Boolean
-
#initialize(pairs, **options) ⇒ Shape
constructor
Instantiate a new ‘NRSER::Types::Shape`.
-
#test?(value) ⇒ Boolean
Instance Methods ======================================================================.
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_s, #union, #xor
Constructor Details
Instance Attribute Details
#pairs ⇒ Hash (readonly)
TODO document ‘pairs` attribute.
20 21 22 |
# File 'lib/nrser/types/shape.rb', line 20 def pairs @pairs end |
Instance Method Details
#custom_from_data(data) ⇒ Object
65 66 67 68 69 |
# File 'lib/nrser/types/shape.rb', line 65 def custom_from_data data pairs.map { |key, type| [ key, type.from_data( data[key] ) ] }.to_h end |
#explain ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nrser/types/shape.rb', line 48 def explain inner = @pairs.map { |k, v| "[#{ k.inspect }]→#{ v.name }" }.join( ", " ) if @pairs.count == 1 inner else '(' + inner + ')' end end |
#has_from_data? ⇒ Boolean
60 61 62 |
# File 'lib/nrser/types/shape.rb', line 60 def has_from_data? pairs.values.all? { |type| type.has_from_data? } end |
#test?(value) ⇒ Boolean
Instance Methods
38 39 40 41 42 43 44 45 46 |
# File 'lib/nrser/types/shape.rb', line 38 def test? value begin @pairs.all? { |k, v| v === value[k] } rescue false end end |