Class: AutoTypeDoc::MethodInfo
- Inherits:
-
Object
- Object
- AutoTypeDoc::MethodInfo
- Defined in:
- lib/auto_type_doc/method_info.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#return_types ⇒ Object
Returns the value of attribute return_types.
-
#source_location ⇒ Object
Returns the value of attribute source_location.
Instance Method Summary collapse
- #add_argument(name:, type:, kind:, position:) ⇒ Object
- #add_return_type(type) ⇒ Object
- #argument(name) ⇒ Object
-
#initialize(source_location:) ⇒ MethodInfo
constructor
A new instance of MethodInfo.
- #most_frequent_arg_type(arg_name) ⇒ String
- #most_frequent_return_type ⇒ String
- #source_file ⇒ Object
- #source_line ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(source_location:) ⇒ MethodInfo
Returns a new instance of MethodInfo.
7 8 9 10 11 |
# File 'lib/auto_type_doc/method_info.rb', line 7 def initialize(source_location:) @source_location = source_location @arguments = Set.new @return_types = Hash.new(0) end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
3 4 5 |
# File 'lib/auto_type_doc/method_info.rb', line 3 def arguments @arguments end |
#return_types ⇒ Object
Returns the value of attribute return_types.
4 5 6 |
# File 'lib/auto_type_doc/method_info.rb', line 4 def return_types @return_types end |
#source_location ⇒ Object
Returns the value of attribute source_location.
5 6 7 |
# File 'lib/auto_type_doc/method_info.rb', line 5 def source_location @source_location end |
Instance Method Details
#add_argument(name:, type:, kind:, position:) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/auto_type_doc/method_info.rb', line 25 def add_argument(name:, type:, kind:, position:) if (a = argument(name)) a.add_type(type) else a = Argument.new(name: name, kind: kind, position: position) a.add_type(type) arguments << a end end |
#add_return_type(type) ⇒ Object
35 36 37 |
# File 'lib/auto_type_doc/method_info.rb', line 35 def add_return_type(type) return_types[type.to_s] += 1 end |
#argument(name) ⇒ Object
21 22 23 |
# File 'lib/auto_type_doc/method_info.rb', line 21 def argument(name) arguments.find { |a| a.name == name.to_s } end |
#most_frequent_arg_type(arg_name) ⇒ String
40 41 42 |
# File 'lib/auto_type_doc/method_info.rb', line 40 def most_frequent_arg_type(arg_name) most_frequent_type(argument(arg_name).types) end |
#most_frequent_return_type ⇒ String
45 46 47 |
# File 'lib/auto_type_doc/method_info.rb', line 45 def most_frequent_return_type most_frequent_type(return_types) end |
#source_file ⇒ Object
13 14 15 |
# File 'lib/auto_type_doc/method_info.rb', line 13 def source_file source_location[0] end |
#source_line ⇒ Object
17 18 19 |
# File 'lib/auto_type_doc/method_info.rb', line 17 def source_line source_location[1] end |
#to_h ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/auto_type_doc/method_info.rb', line 49 def to_h h = {} h[:arguments] = arguments.map(&:to_h) if arguments.any? h.merge( return_types: return_types, source_location: { path: source_file, line: source_line } ) end |
#to_json(*args) ⇒ Object
61 62 63 |
# File 'lib/auto_type_doc/method_info.rb', line 61 def to_json(*args) to_h.to_json(*args) end |