Class: Keepachangelog::Parser

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

Direct Known Subclasses

MarkdownParser, YamlParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.


5
6
7
# File 'lib/keepachangelog/parser.rb', line 5

def initialize
  self.parsed_content = { 'versions' => {} }
end

Instance Attribute Details

#parsed_contentObject

Returns the value of attribute parsed_content


3
4
5
# File 'lib/keepachangelog/parser.rb', line 3

def parsed_content
  @parsed_content
end

Instance Method Details

#to_jsonObject

Changelog in JSON format

Example: “`json {“1.0.0”: { “changes”: { “New”: [“Feature A”] } } } “`


15
16
17
# File 'lib/keepachangelog/parser.rb', line 15

def to_json
  parsed_content.to_json
end

#to_mdObject

Changelog as Markdown


47
48
49
50
51
52
53
54
55
# File 'lib/keepachangelog/parser.rb', line 47

def to_md
  require 'keepachangelog/printer/markdown'
  p = MarkdownPrinter.new(parsed_content['versions'],
                          title: parsed_content['title'],
                          intro: parsed_content['intro'],
                          section_order: parsed_content['section_order'],
                          url: parsed_content['url'])
  p.to_s
end

#to_sObject

Changelog as a Ruby string

Example: “`ruby A”]} “`


42
43
44
# File 'lib/keepachangelog/parser.rb', line 42

def to_s
  parsed_content.to_s
end

#to_yaml(path = nil) ⇒ Object

Changelog in YAML format

Example: “`yaml


0.1.0:

changes:
  New:
  - Feature A

“`


29
30
31
32
33
34
# File 'lib/keepachangelog/parser.rb', line 29

def to_yaml(path = nil)
  path ||= 'changelog'
  require 'keepachangelog/printer/yaml'
  p = YamlPrinter.new(parsed_content)
  p.write(path)
end