Class: NRSER::Types::Attrs

Inherits:
Type
  • Object
show all
Defined in:
lib/nrser/types/attrs.rb

Instance Method Summary collapse

Methods inherited from Type

#check, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #name, #respond_to?, short_name, #to_data, #to_s

Constructor Details

#initialize(attrs, **options) ⇒ Attrs

Returns a new instance of Attrs.



9
10
11
12
13
14
# File 'lib/nrser/types/attrs.rb', line 9

def initialize attrs, **options
  super **options
  @attrs = NRSER.map_values(attrs) { |name, type|
    NRSER::Types.make type
  }
end

Instance Method Details

#default_nameObject



16
17
18
19
20
21
22
# File 'lib/nrser/types/attrs.rb', line 16

def default_name
  attrs_str = @attrs.map { |name, type|
    "#{ name }=#{ type.name }"
  }.join(', ')
  
  "#{ self.class.short_name } #{ attrs_str }"
end

#test(value) ⇒ Object



24
25
26
27
28
# File 'lib/nrser/types/attrs.rb', line 24

def test value
  @attrs.all? { |name, type|
    value.respond_to?(name) && type.test(value.method(name).call)
  }
end