Class: Documentation::Base
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- Documentation::Base
- Extended by:
- Memoized
- Defined in:
- lib/pdoc/parser/documentation_nodes.rb
Instance Method Summary collapse
-
#alias_of ⇒ Object
If instance is tagged as an alias, alias_of returns the corresponding object.
-
#deprecated? ⇒ Boolean
True if the instance was tagged as deprecated.
- #description ⇒ Object
-
#doc_parent ⇒ Object
If instance is a global, returns its Section.
- #ebnf_expressions ⇒ Object
-
#full_name ⇒ Object
Returns the instance’s full_name.
- #inspect ⇒ Object
-
#klass ⇒ Object
Returns the Klass instance if object is a class, nil otherwise.
-
#klass_name ⇒ Object
Returns the instance’s class name.
-
#name ⇒ Object
Returns the instance’s name.
-
#namespace ⇒ Object
Returns the instance’s closests namespace or nil when instance or instance’s Klass is a global.
-
#namespace_string ⇒ Object
Returns the instance’s namespace_string.
- #parent_id ⇒ Object
- #related_to ⇒ Object
-
#root ⇒ Object
Returns an instance of Doc (the root of the tree outputed by the PDoc::Parser).
- #section_name ⇒ Object
- #serialize(serializer) ⇒ Object
- #signature ⇒ Object
- #src_code_line ⇒ Object
-
#tags ⇒ Object
Returns an instance of Tags::Tags.
- #to_yaml ⇒ Object
Methods included from Memoized
avoid_infinite_method_added_loop, memoize, method_added
Instance Method Details
#alias_of ⇒ Object
If instance is tagged as an alias, alias_of returns the corresponding object. It will return nil otherwise.
93 94 95 96 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 93 def alias_of tag = .find { |tag| tag.name == "alias of" } tag.value if tag end |
#deprecated? ⇒ Boolean
True if the instance was tagged as deprecated.
87 88 89 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 87 def deprecated? .include?("deprecated") end |
#description ⇒ Object
156 157 158 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 156 def description text.to_s end |
#doc_parent ⇒ Object
If instance is a global, returns its Section. Else its Namespace.
148 149 150 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 148 def doc_parent namespace ? namespace : section end |
#ebnf_expressions ⇒ Object
152 153 154 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 152 def ebnf_expressions ebnf.elements.map { |e| e.elements.last } end |
#full_name ⇒ Object
Returns the instance’s full_name. For example:
root.find_by_name("Element#update").full_name
# -> "Element#update"
123 124 125 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 123 def full_name ebnf.full_name end |
#inspect ⇒ Object
164 165 166 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 164 def inspect "#<#{self.class} #{full_name}>" end |
#klass ⇒ Object
Returns the Klass instance if object is a class, nil otherwise.
137 138 139 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 137 def klass nil end |
#klass_name ⇒ Object
Returns the instance’s class name.
109 110 111 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 109 def klass_name ebnf.klass_name end |
#name ⇒ Object
Returns the instance’s name. For example:
root.find_by_name("Element#update").name
# -> "update"
116 117 118 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 116 def name ebnf.name end |
#namespace ⇒ Object
Returns the instance’s closests namespace or nil when instance or instance’s Klass is a global.
143 144 145 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 143 def namespace @namespace ||= namespace_string.empty? ? nil : root.find_by_name(namespace_string) end |
#namespace_string ⇒ Object
Returns the instance’s namespace_string. Note that event if the instance is an method or property, the klass_name is not included in that string. So for example:
root.find_by_name("Ajax.Request#request").namespace_string
# -> "Ajax"
132 133 134 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 132 def namespace_string ebnf.namespace end |
#parent_id ⇒ Object
172 173 174 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 172 def parent_id namespace_string.empty? ? section_name : namespace_string end |
#related_to ⇒ Object
98 99 100 101 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 98 def tag = .find { |tag| tag.name == "related to" } tag.value if tag end |
#root ⇒ Object
Returns an instance of Doc (the root of the tree outputed by the PDoc::Parser).
82 83 84 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 82 def root parent.parent.parent end |
#section_name ⇒ Object
176 177 178 179 180 181 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 176 def section_name if .include?('section') value = .find { |tag| tag.name == 'section' }.value "#{value} section" end end |
#serialize(serializer) ⇒ Object
196 197 198 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 196 def serialize(serializer) serializer << to_yaml end |
#signature ⇒ Object
160 161 162 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 160 def signature ebnf.text_value.strip end |
#src_code_line ⇒ Object
168 169 170 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 168 def src_code_line input.line_of(interval.last) - 1 end |
#tags ⇒ Object
Returns an instance of Tags::Tags.
104 105 106 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 104 def start.elements.last.empty? ? [] : start.elements.last end |
#to_yaml ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/pdoc/parser/documentation_nodes.rb', line 183 def to_yaml str = "id: #{full_name.inspect}" str << "\nparent_id: #{parent_id.inspect}" if parent_id str << "\ntype: #{type}" str << "\nsuperclass_id: #{superclass.inspect}" if respond_to?(:superclass) && superclass str << "\nincluded: #{mixins.inspect}" if respond_to?(:mixins) && !mixins.empty? str << "\nline_number: #{src_code_line}" str << "\ndeprecated: true" if deprecated? str << "\nalias_of: #{alias_of.inspect}" if respond_to?(:alias_of) && alias_of str << "\nrelated_to: #{related_to.inspect}" if respond_to?(:related_to) && str << "\ndescription: |\n#{indent(description)}\n" end |