Module: Decanter::Parser::Core::ClassMethods
- Defined in:
- lib/decanter/parser/core.rb
Instance Method Summary collapse
- #_parse(name, value, options = {}) ⇒ Object
-
#allow(*args) ⇒ Object
Set allowed classes.
-
#allowed?(value) ⇒ Boolean
Check for allowed classes.
-
#parse(name, value, options = {}) ⇒ Object
Check if allowed, parse if not.
-
#parser(&block) ⇒ Object
Define parser.
-
#pre(*parsers) ⇒ Object
Set preparsers.
-
#preparsers ⇒ Object
Get prepareer.
Instance Method Details
#_parse(name, value, options = {}) ⇒ Object
11 12 13 |
# File 'lib/decanter/parser/core.rb', line 11 def _parse(name, value, ={}) { name => @parser.call(value, ) } 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
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, ={}) if allowed?(value) { name => value } else _parse(name, value, ) 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 |
#preparsers ⇒ Object
Get prepareer
40 41 42 |
# File 'lib/decanter/parser/core.rb', line 40 def preparsers @pre || [] end |