Module: Jat::Plugins::SimpleApi::FieldsParamParser::InstanceMethods
- Included in:
- Jat::Plugins::SimpleApi::FieldsParamParser
- Defined in:
- lib/jat/plugins/simple_api/lib/fields_param_parser.rb
Constant Summary collapse
- COMMA =
","
- OPEN_BRACKET =
"("
- CLOSE_BRACKET =
")"
Instance Method Summary collapse
-
#parse(fields) ⇒ Object
user => { user: {} } user(id) => { user: { id: {} } } user(id,name) => { user: { id: {}, name: {} } } user,comments => { user: {}, comments: {} } user(comments(text)) => { user: { comments: { text: {} } } }.
Instance Method Details
#parse(fields) ⇒ Object
user => { user: {} } user(id) => { user: { id: {} } } user(id,name) => { user: { id: {}, name: {} } } user,comments => { user: {}, comments: {} } user(comments(text)) => { user: { comments: { text: {} } } }
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jat/plugins/simple_api/lib/fields_param_parser.rb', line 35 def parse(fields) res = {} attribute = +"" path_stack = nil fields.each_char do |char| case char when COMMA add_attribute(res, path_stack, attribute, FROZEN_EMPTY_HASH) when CLOSE_BRACKET add_attribute(res, path_stack, attribute, FROZEN_EMPTY_HASH) path_stack&.pop when OPEN_BRACKET name = add_attribute(res, path_stack, attribute, {}) (path_stack ||= []).push(name) if name else attribute.insert(-1, char) end end add_attribute(res, path_stack, attribute, FROZEN_EMPTY_HASH) res end |