Class: Autodoc::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/autodoc/document.rb

Defined Under Namespace

Classes: Parameter

Constant Summary collapse

DEFAULT_DOCUMENT_PATH_FROM_EXAMPLE =
->(example) do
  example.file_path.gsub(%r<\./spec/[^/]+/(.+)_spec\.rb>, '\1.md')
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, example) ⇒ Document

Returns a new instance of Document.



18
19
20
21
# File 'lib/autodoc/document.rb', line 18

def initialize(context, example)
  @context = context
  @example = example
end

Class Method Details

.render(*args) ⇒ Object



14
15
16
# File 'lib/autodoc/document.rb', line 14

def self.render(*args)
  new(*args).render
end

Instance Method Details

#identifierObject



37
38
39
# File 'lib/autodoc/document.rb', line 37

def identifier
  title.gsub(" ", "-").gsub(/[:\/]/, "").downcase
end

#pathnameObject



23
24
25
26
27
# File 'lib/autodoc/document.rb', line 23

def pathname
  @pathname ||= begin
    Autodoc.configuration.pathname + document_path_from_example.call(example)
  end
end

#renderObject



29
30
31
# File 'lib/autodoc/document.rb', line 29

def render
  ERB.new(Autodoc.configuration.template, nil, "-").result(binding)
end

#titleObject



33
34
35
# File 'lib/autodoc/document.rb', line 33

def title
  "#{method} #{path}"
end