class DocDigger::LineParser
Constants
- COMMANDS
- PARAMETER_LOCATIONS
- PICKS
- RESPONSE_LOCATIONS
Public Class Methods
new(str, clazz)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 9 def initialize(str, clazz) @clazz = clazz pick = PICKS[clazz] @str = pick.nil? ? str : str.gsub(pick, '') end
Public Instance Methods
indentation()
click to toggle source
# File lib/doc-digger/line_parser.rb, line 25 def indentation @indentation ||= @str.match(/\A\s*/)[0].length end
parse()
click to toggle source
# File lib/doc-digger/line_parser.rb, line 15 def parse parts = @str.strip.split(/\s+/) command = parts[0].to_s.match(COMMANDS) if command.nil? || command[1].nil? { type: :joint, text: @str } else send(command[1], parts[1..-1], command) end end
Protected Instance Methods
analyze_arguments(args)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 68 def analyze_arguments(args) { group: args[0].to_s.match(/\((.+)\)/) }.tap do |r| r[:type] = (r[:group].nil? ? args[0] : args[1]).to_s.match(/\{(.+)\}/) r[:names] = args[[r[:group], r[:type]].compact.length].to_s r[:name] = r[:names].match(/\A\[(.+)\]\Z/) r[:default] = (r[:name].nil? ? r[:names] : r[:name][1]).split("=") r[:parent] = r[:default][0].split(".") end end
cmd(args, cmd)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 31 def cmd(args, cmd) { type: :cmd, part: cmd[1].split("_")[1].to_sym, data: { name: args[0] } } end
doc(args, _cmd)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 35 def doc(args, _cmd) { type: :doc, part: :main, data: {} }.tap do |result| m = args[0].match(/\((\w+)\)/) result[:data][:summary] = args[[m].compact.length..-1].join(" ") result[:data][:name] = m[1] unless m.nil? end end
res(args, _cmd)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 43 def res(args, _cmd) { type: :res, part: :main, data: { method: args[0], path: args[1], summary: args[2..-1].join(" ") } } end
res_bind(args, _cmd)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 51 def res_bind(args, _cmd) { type: :res, part: :bind, data: {} }.tap do |result| m = args[0].match(/\((param|header|return|error)\)/) result[:data][:scope] = m[1] unless m.nil? result[:data][:command] = args[[m].compact.length] result[:data][:vars] = args[([m].compact.length + 1)..-1] end end
res_io(args, cmd)
click to toggle source
# File lib/doc-digger/line_parser.rb, line 78 def res_io(args, cmd) { type: :res, part: cmd[4].to_sym, data: {} }.tap do |result| r = analyze_arguments(args) unless r[:type].nil? options = r[:type][1].split("=") array = options[0].match(/(\w+)(\[\])?\Z/) result[:data][:options] = options[1].split(",") if options.length == 2 unless array.nil? result[:data][:array] = !array[2].nil? result[:data][:type] = array[1] end end case result[:part] when :param location = (r[:group] || [])[1] result[:data][:location] = PARAMETER_LOCATIONS === location ? location : 'query' result[:data][:required] = location == "path" || r[:name].nil? result[:data][:default] = r[:default][1] if r[:default].length == 2 result[:data][:name] = r[:parent].length == 1 ? r[:default][0] : r[:parent][-1] when :response location = (r[:group] || [nil, 'body'])[1].split('=') result[:data][:group] = location[1] if location.length > 1 result[:data][:location] = RESPONSE_LOCATIONS === location[0] ? location[0] : 'body' result[:data][:name] = r[:parent].length == 1 ? r[:names] : r[:parent][-1] end result[:data][:parent] = r[:parent][0..-2] if r[:parent].length > 1 result[:data][:summary] = args[([r[:group], r[:type]].compact.length + 1)..-1].join(' ') end end
Also aliased as: res_param, res_response