class ApiBlueprintFormatter::ExampleFormatter

Parses example metadata for Examples (Request+Response) and outputs markdown in accordance with the API Blueprint spec.

Specs:

- https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md#def-request-section
- https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md#response-section

Attributes

example_metadata[R]

Public Class Methods

new(example_description, example_metadata) click to toggle source
# File lib/api_blueprint/example_formatter.rb, line 11
def initialize(example_description, example_metadata)
  @example_description = example_description
  @example_metadata = example_metadata
end

Public Instance Methods

example_description() click to toggle source
# File lib/api_blueprint/example_formatter.rb, line 22
def example_description
  sanitize_api_identifier(@example_description)
end
format() click to toggle source
# File lib/api_blueprint/example_formatter.rb, line 16
def format
  out = ''
  out << format_request
  out << format_response
end

Private Instance Methods

format_location() click to toggle source
# File lib/api_blueprint/example_formatter.rb, line 40
def format_location
  example_metadata[:location].gsub(/:\d+/,'') # remove line numbers from location
end
format_request() click to toggle source
# File lib/api_blueprint/example_formatter.rb, line 28
def format_request
  "+ Request #{example_description}\n" \
  "\n" \
  "        #{example_metadata[:request][:parameters]}\n" \
  "\n" \
  "        Location: #{format_location}\n" \
  "        Source code:\n" \
  "\n" \
  "#{indent_lines(8, example_metadata[:source])}\n" \
  "\n"
end
format_response() click to toggle source
# File lib/api_blueprint/example_formatter.rb, line 44
def format_response
  "+ Response #{example_metadata[:response][:status]} (#{example_metadata[:request][:format]})\n" \
  "\n" \
  "        #{example_metadata[:response][:body]}\n" \
  "\n"
end