Class: Decoradar::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/decoradar/attribute.rb

Direct Known Subclasses

Collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Attribute

Returns a new instance of Attribute.



5
6
7
8
9
# File 'lib/decoradar/attribute.rb', line 5

def initialize(options = {})
  @name = options.fetch(:name)
  @as = options.fetch(:as, @name)
  @include_if = options[:include_if]
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



3
4
5
# File 'lib/decoradar/attribute.rb', line 3

def as
  @as
end

#include_ifObject (readonly)

Returns the value of attribute include_if.



3
4
5
# File 'lib/decoradar/attribute.rb', line 3

def include_if
  @include_if
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/decoradar/attribute.rb', line 3

def name
  @name
end

Instance Method Details

#including?(object) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/decoradar/attribute.rb', line 11

def including?(object)
  case include_if
  when nil then true
  when Proc then include_if.call(object)
  else false
  end
end

#serialize(hash, value) ⇒ Object



19
20
21
# File 'lib/decoradar/attribute.rb', line 19

def serialize(hash, value)
  hash.merge(as => value)
end