Module: Decanter::Parser::Core::ClassMethods

Defined in:
lib/decanter/parser/core.rb

Instance Method Summary collapse

Instance Method Details

#_parse(name, value, options = {}) ⇒ Object



11
12
13
# File 'lib/decanter/parser/core.rb', line 11

def _parse(name, value, options={})
  { name => @parser.call(value, options) }
end

#allow(*args) ⇒ Object

Set allowed classes



30
31
32
# File 'lib/decanter/parser/core.rb', line 30

def allow(*args)
  @allowed = args
end

#allowed?(value) ⇒ Boolean

Check for allowed classes

Returns:

  • (Boolean)


45
46
47
# File 'lib/decanter/parser/core.rb', line 45

def allowed?(value)
  @allowed && @allowed.any? { |allowed| value.is_a? allowed }
end

#parse(name, value, options = {}) ⇒ Object

Check if allowed, parse if not



16
17
18
19
20
21
22
# File 'lib/decanter/parser/core.rb', line 16

def parse(name, value, options={})
  if allowed?(value)
    { name => value }
  else
    _parse(name, value, options)
  end
end

#parser(&block) ⇒ Object

Define parser



25
26
27
# File 'lib/decanter/parser/core.rb', line 25

def parser(&block)
  @parser = block
end

#pre(*parsers) ⇒ Object

Set preparsers



35
36
37
# File 'lib/decanter/parser/core.rb', line 35

def pre(*parsers)
  @pre = parsers
end

#preparsersObject

Get prepareer



40
41
42
# File 'lib/decanter/parser/core.rb', line 40

def preparsers
  @pre || []
end