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.



20
21
22
23
# File 'lib/autodoc/document.rb', line 20

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

Class Method Details

.render(*args) ⇒ Object



16
17
18
# File 'lib/autodoc/document.rb', line 16

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

Instance Method Details

#identifierObject



43
44
45
# File 'lib/autodoc/document.rb', line 43

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

#line_numberObject



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

def line_number
  @context.inspect[/:([\d]+)\)>$/, 1].to_i
end

#pathnameObject



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

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

#renderObject



35
36
37
# File 'lib/autodoc/document.rb', line 35

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

#titleObject



39
40
41
# File 'lib/autodoc/document.rb', line 39

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