Class: PostmanMarkdoc

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

Defined Under Namespace

Classes: CollectionParser, MarkdownGenerator, RequestParser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PostmanMarkdoc

accepts hash representations of postman json collections



23
24
25
26
# File 'lib/postman_markdoc.rb', line 23

def initialize(*args)
  @collections = args
  generate_markdown
end

Instance Attribute Details

#collectionsObject (readonly)

Returns the value of attribute collections.



20
21
22
# File 'lib/postman_markdoc.rb', line 20

def collections
  @collections
end

#markdownObject (readonly)

Returns the value of attribute markdown.



20
21
22
# File 'lib/postman_markdoc.rb', line 20

def markdown
  @markdown
end

Class Method Details

.files_to_markdown(*file_names) ⇒ Object

accepts filenames as arguments returns markdown string



7
8
9
10
11
# File 'lib/postman_markdoc.rb', line 7

def self.files_to_markdown(*file_names)
  raw_json = file_names.map{|f| IO.read(f)}
  collections = raw_json.map{|json| JSON.parse(json)}
  self.new(*collections).markdown
end

.raw_json_to_markdown(raw_json) ⇒ Object

accepts raw json collection string as argument returns markdown string



15
16
17
18
# File 'lib/postman_markdoc.rb', line 15

def self.raw_json_to_markdown(raw_json)
  collection = JSON.parse(raw_json)
  self.new(collection).markdown
end

Instance Method Details

#generate_markdownObject



28
29
30
31
32
33
34
35
# File 'lib/postman_markdoc.rb', line 28

def generate_markdown
  @markdown = ""
  collections.each do |collection|
    @markdown << PostmanMarkdoc::MarkdownGenerator.generate(
                   data: collection
                  ).content
  end
end