changelog_memo-parser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/changelog_memo-parser.gemspec +19 -0
- data/lib/changelog_memo/entry.rb +19 -0
- data/lib/changelog_memo/parser.rb +80 -0
- data/lib/changelog_memo-parser/version.rb +5 -0
- data/lib/changelog_memo-parser.rb +3 -0
- data/spec/changelog_memo-parser_spec.rb +46 -0
- data/spec/fixture/clmemo.txt +17 -0
- metadata +60 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 koyachi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# ChangelogMemo::Parser
|
2
|
+
|
3
|
+
Pase changelog memo text.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'changelog_memo-parser'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install changelog_memo-parser
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
data = ChangelogMemo::Parser.pase("/path/to/your/changelog_memo")
|
23
|
+
pp data
|
24
|
+
```
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'changelog_memo-parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "changelog_memo-parser"
|
8
|
+
gem.version = ChangelogMemo::Parser::VERSION
|
9
|
+
gem.authors = ["koyachi"]
|
10
|
+
gem.email = ["rtk2106@gmail.com"]
|
11
|
+
gem.description = %q{Parse changelog memo text.}
|
12
|
+
gem.summary = %q{Parse changelog memo text.}
|
13
|
+
gem.homepage = "https://github.com/koyachi/ruby-changelog_memo-parser"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ChangelogMemo
|
2
|
+
class Entry
|
3
|
+
attr_accessor :title, :body, :tags, :create_date
|
4
|
+
|
5
|
+
def initialize(title, body, tags, create_date)
|
6
|
+
@title = title
|
7
|
+
@body = body
|
8
|
+
@tags = tags
|
9
|
+
@create_date = create_date
|
10
|
+
end
|
11
|
+
|
12
|
+
def==(other)
|
13
|
+
@title == other.title &&
|
14
|
+
@body == other.body &&
|
15
|
+
@tags == other.tags &&
|
16
|
+
@create_date == other.create_date
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module ChangelogMemo
|
2
|
+
module Parser
|
3
|
+
class << self
|
4
|
+
def parse_file(path)
|
5
|
+
parse_text(open(path).readlines.join(""))
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_text(text)
|
9
|
+
daily_entries(text).map do |daily_entry|
|
10
|
+
entries(daily_entry).map do |e|
|
11
|
+
ChangelogMemo::Entry.new(
|
12
|
+
e[:title],
|
13
|
+
e[:body],
|
14
|
+
e[:tags],
|
15
|
+
[daily_entry[:year], daily_entry[:month], daily_entry[:day]].join('-')
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end.flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def daily_entries(text)
|
23
|
+
org_text = text
|
24
|
+
offset = 0
|
25
|
+
total_offset = 0
|
26
|
+
total_length = text.length
|
27
|
+
results = []
|
28
|
+
prev_day = nil
|
29
|
+
while total_offset < text.length
|
30
|
+
re = /^((?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) \(.*?\) (?<author>.*?) <(?<email>.*?)>)/
|
31
|
+
md = re.match(text)
|
32
|
+
break if md.nil?
|
33
|
+
break unless md[:year] and md[:month] and md[:day]
|
34
|
+
|
35
|
+
current_day = {
|
36
|
+
:year => md[:year],
|
37
|
+
:month => md[:month],
|
38
|
+
:day => md[:day],
|
39
|
+
:author => md[:author],
|
40
|
+
:email => md[:email],
|
41
|
+
:search_offset => offset,
|
42
|
+
:offset => total_offset + md.begin(:year),
|
43
|
+
:length => 0,
|
44
|
+
:text => nil
|
45
|
+
}
|
46
|
+
if prev_day
|
47
|
+
prev_day[:length] = current_day[:offset] - prev_day[:offset]
|
48
|
+
extract_text(org_text, prev_day)
|
49
|
+
end
|
50
|
+
results.push(current_day)
|
51
|
+
offset = md.end(:email) + 2
|
52
|
+
total_offset += offset
|
53
|
+
text = text[offset..-1]
|
54
|
+
prev_day = results[-1]
|
55
|
+
end
|
56
|
+
prev_day[:length] = total_length
|
57
|
+
extract_text(org_text, prev_day)
|
58
|
+
results
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_text(text, daily_entry)
|
62
|
+
daily_entry[:text] = text[daily_entry[:offset], daily_entry[:length]]
|
63
|
+
end
|
64
|
+
|
65
|
+
def entries(daily_entry)
|
66
|
+
entries = daily_entry[:text].split("\n\n")[1..-1]
|
67
|
+
entries.map do |entry_text|
|
68
|
+
re = /\A\t\* (?<tags>.*?):\s*(?<title>.*?)\n\t(?<body>.*?)\Z/m
|
69
|
+
md = re.match(entry_text)
|
70
|
+
entry = {
|
71
|
+
:title => md[:title],
|
72
|
+
:tags => md[:tags].split(',').map { |t| t.strip },
|
73
|
+
:body => md[:body].split("\n\t").join("\n")
|
74
|
+
}
|
75
|
+
entry
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'changelog_memo-parser'
|
5
|
+
|
6
|
+
describe 'ChangelogMemo::Parser' do
|
7
|
+
let(:input_text) do
|
8
|
+
<<-TEXT
|
9
|
+
2012-03-13 (Tue) t.koyachi@home <sample@test.com>
|
10
|
+
|
11
|
+
* tag1: title1
|
12
|
+
body-line1
|
13
|
+
body-line2
|
14
|
+
|
15
|
+
2012-03-12 (Mon) t.koyachi@home <sample@test.com>
|
16
|
+
|
17
|
+
* tag2: title2
|
18
|
+
body2-line1
|
19
|
+
|
20
|
+
* tag3_1, tag3_2: title3
|
21
|
+
body3-line1
|
22
|
+
body3-line2
|
23
|
+
|
24
|
+
TEXT
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should parse_text' do
|
28
|
+
ChangelogMemo::Parser.parse_text(input_text).should ==(
|
29
|
+
[
|
30
|
+
ChangelogMemo::Entry.new("title1", "body-line1\nbody-line2", ["tag1"], "2012-03-13"),
|
31
|
+
ChangelogMemo::Entry.new("title2", "body2-line1", ["tag2"], "2012-03-12"),
|
32
|
+
ChangelogMemo::Entry.new("title3", "body3-line1\nbody3-line2", ["tag3_1", "tag3_2"], "2012-03-12"),
|
33
|
+
])
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:clmemo_file_path) { File.expand_path(File.dirname(__FILE__) + '/fixture/clmemo.txt') }
|
37
|
+
it 'should parse_file' do
|
38
|
+
ChangelogMemo::Parser.parse_file(clmemo_file_path).should ==(
|
39
|
+
[
|
40
|
+
ChangelogMemo::Entry.new("title1 from clmemo.txt", "body-line1\nbody-line2", ["tag1"], "2012-03-13"),
|
41
|
+
ChangelogMemo::Entry.new("title2 from clmemo.txt", "body2-line1", ["tag2"], "2012-03-12"),
|
42
|
+
ChangelogMemo::Entry.new("title3 from clmemo.txt", "body3-line1\nbody3-line2", ["tag3_1", "tag3_2"], "2012-03-12"),
|
43
|
+
ChangelogMemo::Entry.new("title4 from clmemo.txt", "body4-line1", ["tag4_1"], "2012-03-12"),
|
44
|
+
])
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
2012-03-13 (Tue) t.koyachi@home <sample@test.com>
|
2
|
+
|
3
|
+
* tag1: title1 from clmemo.txt
|
4
|
+
body-line1
|
5
|
+
body-line2
|
6
|
+
|
7
|
+
2012-03-12 (Mon) t.koyachi@home <sample@test.com>
|
8
|
+
|
9
|
+
* tag2: title2 from clmemo.txt
|
10
|
+
body2-line1
|
11
|
+
|
12
|
+
* tag3_1, tag3_2: title3 from clmemo.txt
|
13
|
+
body3-line1
|
14
|
+
body3-line2
|
15
|
+
|
16
|
+
* tag4_1: title4 from clmemo.txt
|
17
|
+
body4-line1
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: changelog_memo-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- koyachi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Parse changelog memo text.
|
15
|
+
email:
|
16
|
+
- rtk2106@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- changelog_memo-parser.gemspec
|
28
|
+
- lib/changelog_memo-parser.rb
|
29
|
+
- lib/changelog_memo-parser/version.rb
|
30
|
+
- lib/changelog_memo/entry.rb
|
31
|
+
- lib/changelog_memo/parser.rb
|
32
|
+
- spec/changelog_memo-parser_spec.rb
|
33
|
+
- spec/fixture/clmemo.txt
|
34
|
+
homepage: https://github.com/koyachi/ruby-changelog_memo-parser
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.23
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Parse changelog memo text.
|
58
|
+
test_files:
|
59
|
+
- spec/changelog_memo-parser_spec.rb
|
60
|
+
- spec/fixture/clmemo.txt
|