Class: Serialisable::Selector Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/serialisable/selector.rb

Overview

This class is abstract.

Must implement #match

Direct Known Subclasses

Attribute, Nested, NestedMultiple, Node, Nodes

Defined Under Namespace

Classes: Attribute, Nested, NestedMultiple, Node, Nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, selector, type = nil) ⇒ Selector



7
8
9
10
11
# File 'lib/serialisable/selector.rb', line 7

def initialize(name, selector, type = nil)
  @name = name
  @selector = selector
  @type = type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



5
6
7
# File 'lib/serialisable/selector.rb', line 5

def name
  @name
end

Instance Method Details

#parse(value) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/serialisable/selector.rb', line 13

def parse(value)
  if @type.respond_to?(:parse)
    @type.parse(value)
  elsif @type.is_a?(Symbol)
    value.send(@type)
  else
    value
  end
end