changelog 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ = Version 0.5
2
+ * Ordering is solved by ReverseHashMixin.
3
+
1
4
  = Version 0.4
2
5
  * Fixed the order, the first version is supposed to be at the bottom, not at the top.
3
6
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 – 2010 Jakub Šťastný aka Botanicus
1
+ Copyright (c) 2009 – 2011 Jakub Šťastný aka Botanicus
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -8,7 +8,7 @@ require "base64"
8
8
 
9
9
  Gem::Specification.new do |s|
10
10
  s.name = "changelog"
11
- s.version = "0.4"
11
+ s.version = "0.5"
12
12
  s.authors = ["Jakub Šťastný aka Botanicus"]
13
13
  s.homepage = "http://github.com/botanicus/changelog"
14
14
  s.summary = "Simple CHANGELOG parser for Ruby 1.9"
@@ -1,6 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class CHANGELOG
4
+ module ReverseHashMixin
5
+ def reverse
6
+ self.keys.reverse.reduce(Hash.new) do |hash, key|
7
+ hash.merge(key => self[key])
8
+ end
9
+ end
10
+ end
11
+
4
12
  # @param [String] path Path to your CHANGELOG file
5
13
  # @raise [ArgumentError] if given path doesn't exist
6
14
  # @author Jakub Stastny aka Botanicus
@@ -22,7 +30,7 @@ class CHANGELOG
22
30
  # @author Jakub Stastny aka Botanicus
23
31
  # @since 0.0.1
24
32
  def last_version_name
25
- self.versions.first
33
+ self.versions.last
26
34
  end
27
35
 
28
36
  # @return [Array<String>, nil]
@@ -33,7 +41,7 @@ class CHANGELOG
33
41
  # changelog.version_changes
34
42
  # changelog.version_changes("Version 0.1")
35
43
  # changelog.version_changes(/0\.1/)
36
- def version_changes(version = self.versions.first)
44
+ def version_changes(version = self.last_version_name)
37
45
  self.parse[version].inject(String.new) do |buffer, line|
38
46
  buffer += "[\e[32m#{version}\e[0m] #{line}\n"
39
47
  end
@@ -76,19 +84,26 @@ class CHANGELOG
76
84
  # @author Jakub Stastny aka Botanicus
77
85
  # @since 0.0.1
78
86
  def parse
79
- @result ||= begin
80
- lines = File.readlines(@path)
81
- lines.inject([nil, Hash.new]) do |pair, line|
82
- version, hash = pair
83
- if line.match(/^=/)
84
- version = line.chomp.sub(/^= /, "")
85
- hash[version] = Array.new
86
- elsif line.match(/^\s+\* /)
87
- hash[version].push(line.chomp.sub(/^\s+\* /, ""))
88
- else # skip empty lines
89
- end
90
- [version, hash]
91
- end.last
87
+ @hash ||= begin
88
+ hash = __parse__.last
89
+ hash.extend(ReverseHashMixin)
90
+ hash.reverse
91
+ end
92
+ end
93
+
94
+ protected
95
+ def __parse__
96
+ lines = File.readlines(@path)
97
+ lines.inject([nil, Hash.new]) do |pair, line|
98
+ version, hash = pair
99
+ if line.match(/^=/)
100
+ version = line.chomp.sub(/^= /, "")
101
+ hash[version] = Array.new
102
+ elsif line.match(/^\s+\* /)
103
+ hash[version].push(line.chomp.sub(/^\s+\* /, ""))
104
+ else # skip empty lines
105
+ end
106
+ [version, hash]
92
107
  end
93
108
  end
94
109
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require_relative "../lib/changelog"
3
+ require "changelog"
4
4
 
5
5
  describe CHANGELOG do
6
6
  before(:each) do
@@ -16,8 +16,8 @@ describe CHANGELOG do
16
16
 
17
17
  describe "#versions" do
18
18
  it "should return all versions described in the CHANGELOG" do
19
- versions = ["Version 0.2.1", "Version 0.2.0", "Version 0.1.2",
20
- "Version 0.1.1", "Version 0.1", "Version 0.0.1 Miracle Born"]
19
+ versions = ["Version 0.0.1 Miracle Born", "Version 0.1",
20
+ "Version 0.1.1", "Version 0.1.2", "Version 0.2.0", "Version 0.2.1"]
21
21
  @changelog.versions.should eql(versions)
22
22
  end
23
23
  end
@@ -54,7 +54,7 @@ describe CHANGELOG do
54
54
 
55
55
  describe "#select" do
56
56
  it "should return {version => [changes]} hash for all the versions matching given pattern" do
57
- versions = ["Version 0.1.2", "Version 0.1.1", "Version 0.1"]
57
+ versions = ["Version 0.1", "Version 0.1.1", "Version 0.1.2"]
58
58
  @changelog.select(/^Version 0.1/).keys.should eql(versions)
59
59
  end
60
60
  end
metadata CHANGED
@@ -4,15 +4,15 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- version: "0.4"
7
+ - 5
8
+ version: "0.5"
9
9
  platform: ruby
10
10
  authors:
11
11
  - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain:
15
- date: 2011-01-18 00:00:00 +00:00
15
+ date: 2011-02-21 00:00:00 +00:00
16
16
  default_executable:
17
17
  dependencies: []
18
18
 
@@ -38,7 +38,7 @@ has_rdoc: true
38
38
  homepage: http://github.com/botanicus/changelog
39
39
  licenses: []
40
40
 
41
- post_install_message: "[\e[32mVersion 0.4\e[0m] Fixed the order, the first version is supposed to be at the bottom, not at the top.\n"
41
+ post_install_message: "[\e[32mVersion 0.5\e[0m] Ordering is solved by ReverseHashMixin.\n"
42
42
  rdoc_options: []
43
43
 
44
44
  require_paths: