Class: NRSER::Types::Shape
Overview
Instance Attribute Summary collapse
-
#pairs ⇒ Hash
readonly
TODO document ‘pairs` attribute.
Display Instance Methods collapse
- #default_symbolic ⇒ Object
- #explain ⇒ Object
-
#string_format(pre:, post:, method:, spaces: true) ⇒ Object
————————————————————————–.
Instance Method Summary collapse
- #custom_from_data(data) ⇒ 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!, #default_name, #from_data, #from_s, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #symbolic, #test, #to_data, #to_proc, #to_s, #union, #xor
Constructor Details
Instance Attribute Details
#pairs ⇒ Hash (readonly)
TODO document ‘pairs` attribute.
44 45 46 |
# File 'lib/nrser/types/shape.rb', line 44 def pairs @pairs end |
Instance Method Details
#custom_from_data(data) ⇒ Object
108 109 110 111 112 |
# File 'lib/nrser/types/shape.rb', line 108 def custom_from_data data pairs.map { |key, type| [ key, type.from_data( data[key] ) ] }.to_h end |
#default_symbolic ⇒ Object
91 92 93 |
# File 'lib/nrser/types/shape.rb', line 91 def default_symbolic string_format pre: '{', post: '}', method: :symbolic end |
#explain ⇒ Object
96 97 98 |
# File 'lib/nrser/types/shape.rb', line 96 def explain string_format pre: 'Shape<', post: '>', method: :explain end |
#has_from_data? ⇒ Boolean
103 104 105 |
# File 'lib/nrser/types/shape.rb', line 103 def has_from_data? pairs.values.all? { |type| type.has_from_data? } end |
#string_format(pre:, post:, method:, spaces: true) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/nrser/types/shape.rb', line 74 def string_format pre:, post:, method:, spaces: true space = spaces ? ' ' : '' inner = @pairs.map { |k, v| key_part = if k.is_a? Symbol "#{ k }:#{ space }" else "#{ k.inspect }#{ space }=>#{ space }" end key_part + v.public_send( method ) } pre + inner.join( ",#{ space }" ) + post end |
#test?(value) ⇒ Boolean
Instance Methods
62 63 64 65 66 67 68 |
# File 'lib/nrser/types/shape.rb', line 62 def test? value begin @pairs.all? { |k, v| v === value[k] } rescue false end end |