Class: CHANGELOG
- Inherits:
-
Object
- Object
- CHANGELOG
- Defined in:
- lib/changelog.rb
Defined Under Namespace
Modules: ReverseHashMixin
Constant Summary collapse
- Hash =
OrderedHash
Instance Method Summary collapse
-
#[](version) ⇒ Array<String>?
List of changes in the given version or nil if given version doesn’t exist.
-
#initialize(path = "CHANGELOG") ⇒ CHANGELOG
constructor
A new instance of CHANGELOG.
-
#last_version_name ⇒ String?
Name of the last available version or nil if the changelog is empty.
-
#parse ⇒ Hash
Hash of ‘=> changes` for the whole changelog.
-
#select(pattern) ⇒ Hash
Hash of ‘=> changes` for matched versions.
-
#version_changes(version = self.last_version_name) ⇒ Array<String>?
List of changes in the last version or nil if the changelog is empty.
-
#versions ⇒ Array<String>
List of all the available versions.
Constructor Details
#initialize(path = "CHANGELOG") ⇒ CHANGELOG
Returns a new instance of CHANGELOG.
22 23 24 25 |
# File 'lib/changelog.rb', line 22 def initialize(path = "CHANGELOG") raise ArgumentError, "Path '#{path}' doesn't exist!" unless File.exist?(path) @path = path end |
Instance Method Details
#[](version) ⇒ Array<String>?
Returns List of changes in the given version or nil if given version doesn’t exist.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/changelog.rb', line 63 def [](version) if version.is_a?(String) self.parse[version] else versions = self.select(version).keys if versions.length > 1 raise StandardError, "More than one version was matched: #{versions.inspect}" elsif versions.empty? return nil else self[versions.first] end end end |
#last_version_name ⇒ String?
Returns Name of the last available version or nil if the changelog is empty.
38 39 40 |
# File 'lib/changelog.rb', line 38 def last_version_name self.versions.last end |
#parse ⇒ Hash
Returns Hash of ‘=> changes` for the whole changelog.
92 93 94 95 96 97 98 |
# File 'lib/changelog.rb', line 92 def parse @hash ||= begin hash = __parse__.last hash.extend(ReverseHashMixin) hash.reverse end end |
#select(pattern) ⇒ Hash
Returns Hash of ‘=> changes` for matched versions.
83 84 85 86 87 |
# File 'lib/changelog.rb', line 83 def select(pattern) self.parse.select do |version, changes| version.match(pattern) end end |
#version_changes(version = self.last_version_name) ⇒ Array<String>?
Returns List of changes in the last version or nil if the changelog is empty.
50 51 52 53 54 |
# File 'lib/changelog.rb', line 50 def version_changes(version = self.last_version_name) self.parse[version].inject(String.new) do |buffer, line| buffer += "[\e[32m#{version}\e[0m] #{line}\n" end end |
#versions ⇒ Array<String>
Returns List of all the available versions.
30 31 32 |
# File 'lib/changelog.rb', line 30 def versions self.parse.keys end |