Class: Nexmo::OAS::Renderer::Presenters::ApiSpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo/oas/renderer/presenters/api_specification.rb

Instance Method Summary collapse

Constructor Details

#initialize(document_name:, code_language: nil) ⇒ ApiSpecification

Returns a new instance of ApiSpecification.



8
9
10
11
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 8

def initialize(document_name:, code_language: nil)
  @document_name = document_name
  @code_language = code_language
end

Instance Method Details

#contentObject



45
46
47
48
49
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 45

def content
  options = {}
  options.merge(code_language: @code_language) if @code_language
  @content ||= Nexmo::Markdown::Renderer.new(options).call(document)
end

#documentObject



29
30
31
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 29

def document
  @document ||= File.read(document_path)
end

#document_pathObject



21
22
23
24
25
26
27
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 21

def document_path
  if defined?(NexmoDeveloper::Application)
    "#{Rails.configuration.docs_base_path}/_api/#{@document_name}.md"
  else
    "_api/#{@document_name}.md"
  end
end

#document_titleObject



41
42
43
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 41

def document_title
  @document_title ||= "#{side_navigation_title} > #{frontmatter.fetch('title')}"
end

#frontmatterObject



33
34
35
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 33

def frontmatter
  @frontmatter ||= YAML.safe_load(document)
end

#side_navigationObject



13
14
15
16
17
18
19
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 13

def side_navigation
  if defined?(NexmoDeveloper::Application)
    "#{Rails.configuration.docs_base_path}/api/#{@document_name}"
  else
    "api/#{@document_name}"
  end
end

#side_navigation_titleObject



37
38
39
# File 'lib/nexmo/oas/renderer/presenters/api_specification.rb', line 37

def side_navigation_title
  @side_navigation_title ||= frontmatter.fetch('api')
end