Class: MethodParser
- Inherits:
-
Object
- Object
- MethodParser
- Defined in:
- lib/method_parser.rb
Overview
Parses method code
Instance Attribute Summary collapse
-
#cmd_opts ⇒ Object
Returns the value of attribute cmd_opts.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#option_tags ⇒ Object
readonly
Returns the value of attribute option_tags.
-
#param_tags ⇒ Object
readonly
Returns the value of attribute param_tags.
Instance Method Summary collapse
-
#default_params ⇒ Hash
Default values for parameters.
-
#initialize(method) ⇒ MethodParser
constructor
A new instance of MethodParser.
-
#option_tags_names ⇒ Array(String)
Names of options.
-
#options_group?(param_name) ⇒ Boolean
Check if the name is an option.
-
#param_tags_names ⇒ Array(String)
Names of parameters.
-
#params_array ⇒ Object
Prepare.
Constructor Details
#initialize(method) ⇒ MethodParser
Returns a new instance of MethodParser.
11 12 13 14 15 16 17 18 |
# File 'lib/method_parser.rb', line 11 def initialize(method) @method = method @name = @method.name @parameters = @method.parameters @param_tags = FileParser. @method @option_tags = FileParser. @method @cmd_opts = nil end |
Instance Attribute Details
#cmd_opts ⇒ Object
Returns the value of attribute cmd_opts.
8 9 10 |
# File 'lib/method_parser.rb', line 8 def cmd_opts @cmd_opts end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/method_parser.rb', line 3 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/method_parser.rb', line 3 def name @name end |
#option_tags ⇒ Object (readonly)
Returns the value of attribute option_tags.
3 4 5 |
# File 'lib/method_parser.rb', line 3 def @option_tags end |
#param_tags ⇒ Object (readonly)
Returns the value of attribute param_tags.
3 4 5 |
# File 'lib/method_parser.rb', line 3 def @param_tags end |
Instance Method Details
#default_params ⇒ Hash
Returns default values for parameters.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/method_parser.rb', line 75 def default_params @parameters.map do |array| array.map do |a| if a ['"', "'"].include?(a[0]) && ['"', "'"].include?(a[-1]) ? a[1..-2] : a else a end end end.to_h end |
#option_tags_names ⇒ Array(String)
Returns Names of options.
62 63 64 |
# File 'lib/method_parser.rb', line 62 def .map { |t| t.pair.name.delete(':') } end |
#options_group?(param_name) ⇒ Boolean
Check if the name is an option
70 71 72 |
# File 'lib/method_parser.rb', line 70 def (param_name) .any? { |t| t.name == param_name } end |
#param_tags_names ⇒ Array(String)
Returns Names of parameters.
57 58 59 |
# File 'lib/method_parser.rb', line 57 def .map(&:name) end |
#params_array ⇒ Object
Prepare
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/method_parser.rb', line 21 def params_array expected_params = @parameters.map(&:first).map.with_index { |p, i| [i, p] }.to_h = {} get_params = {} expected_params.each do |index, name| if (name) [index] = name get_params[index] = option_as_hash(name) else get_params[index] = @cmd_opts[name.to_sym] end end get_params = get_params.to_a.sort_by { |a| a[0] }.reverse stop_delete = false get_params.delete_if do |a| index = a[0] value = a[1] result = false if [index] result = value == {} else result = value == nil end stop_delete = true unless result next if stop_delete result end get_params.sort_by { |a| a[0] }.map { |a| a[1] } end |