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

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

Instance Method Summary collapse

Instance Method Details

#allow(*args) ⇒ Object

Set allowed classes



27
28
29
# File 'lib/decanter/parser/core.rb', line 27

def allow(*args)
  @allowed = args
end

#allowed?(values) ⇒ Boolean

Check for allowed classes

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/decanter/parser/core.rb', line 42

def allowed?(values)
  @allowed && Array.wrap(values).all? do |value|
    @allowed.any? { |allowed| value.is_a? allowed }
  end
end

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

Check if allowed, parse if not



12
13
14
15
16
17
18
19
# File 'lib/decanter/parser/core.rb', line 12

def parse(name, values, options={})
  case
  when allowed?(values)
    { name => values }
  else
    _parse(name, values, options)
  end
end

#parser(&block) ⇒ Object

Define parser



22
23
24
# File 'lib/decanter/parser/core.rb', line 22

def parser(&block)
  @parser = block
end

#pre(*parsers) ⇒ Object

Set preparsers



32
33
34
# File 'lib/decanter/parser/core.rb', line 32

def pre(*parsers)
  @pre = parsers
end

#preparsersObject

Get prepareer



37
38
39
# File 'lib/decanter/parser/core.rb', line 37

def preparsers
  @pre || []
end