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_s, #has_from_s?, #name, #respond_to?, short_name, #to_s

Constructor Details

#initialize(attrs, **options) ⇒ Attrs

Returns a new instance of Attrs.



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

def initialize attrs, **options
  super **options
  @attrs = attrs
end

Instance Method Details

#default_nameObject



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

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

#test(value) ⇒ Object



22
23
24
25
26
# File 'lib/nrser/types/attrs.rb', line 22

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