class NRSER::Types::Attributes
Specify types for value attributes.
@note
Construct {Attributes} types using the {.Attributes} factory.
Attributes
types[R]
Attribute types by name.
@return [Hash<Symbol, Type>]
Public Class Methods
new(attrs, **options)
click to toggle source
Construct an `AttrsType`.
@param [Hash<#to_sym, TYPE>] attrs
Map of attribute names to their types (`TYPE` values will be passed through {NRSER::Types.make} to get a type instance). May not be empty.
Calls superclass method
# File lib/nrser/types/attributes.rb, line 54 def initialize attrs, **options super **options if attrs.empty? raise ArgumentError, "Must provide at least one attribute name/type pair" end @types = attrs.map { |k, v| [ k.to_sym, NRSER::Types.make( v ) ] }.to_h.freeze end
Public Instance Methods
default_name()
click to toggle source
# File lib/nrser/types/attributes.rb, line 78 def default_name type_strings = self.type_strings method: :name if type_strings.length == 1 type_strings[0] else L_PAREN + type_strings.join( " #{ AND } " ) + R_PAREN end end
default_symbolic()
click to toggle source
# File lib/nrser/types/attributes.rb, line 89 def default_symbolic type_strings = self.type_strings method: :symbolic if type_strings.length == 1 type_strings[0] else L_PAREN + type_strings.join( " #{ AND } " ) + R_PAREN end end
explain()
click to toggle source
@see NRSER::Types::Type#explain
@return [String]
# File lib/nrser/types/attributes.rb, line 104 def explain "#{ self.class.demod_name }<" + type_strings( method: :explain ).join( ', ' ) + ">" end
test?(value)
click to toggle source
@return [Boolean]
# File lib/nrser/types/attributes.rb, line 115 def test? value types.all? { |name, type| value.respond_to?( name ) && type.test?( value.method( name ).call ) } end
type_strings(method: types.map { |name, type| "
click to toggle source
@!group Display Instance Methods
# File lib/nrser/types/attributes.rb, line 71 def type_strings method: types.map { |name, type| "##{ name }#{ RESPONDS_WITH }#{ type.public_send method }" } end