tidtools 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -1
- data/Manifest.txt +4 -0
- data/bin/twmerge +15 -0
- data/lib/tidtools/tweet.rb +113 -0
- data/lib/tidtools.rb +1 -1
- data/lib/twmerge/cli.rb +30 -0
- metadata +7 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -5,11 +5,14 @@ README.rdoc
|
|
5
5
|
Rakefile
|
6
6
|
bin/tidgrep
|
7
7
|
bin/twgrep
|
8
|
+
bin/twmerge
|
8
9
|
lib/tidgrep/cli.rb
|
9
10
|
lib/tidtools.rb
|
10
11
|
lib/tidtools/platform.rb
|
11
12
|
lib/tidtools/tiddle.rb
|
13
|
+
lib/tidtools/tweet.rb
|
12
14
|
lib/twgrep/cli.rb
|
15
|
+
lib/twmerge/cli.rb
|
13
16
|
script/console
|
14
17
|
script/destroy
|
15
18
|
script/generate
|
@@ -17,3 +20,4 @@ test/test_helper.rb
|
|
17
20
|
test/test_tidgrep_cli.rb
|
18
21
|
test/test_tidtools.rb
|
19
22
|
test/test_twgrep_cli.rb
|
23
|
+
test/test_twmerge_cli.rb
|
data/bin/twmerge
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
# Created on 2010-5-2.
|
5
|
+
# Copyright (c) 2010. All rights reserved.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/tidtools")
|
9
|
+
require "twmerge/cli"
|
10
|
+
|
11
|
+
# バージョン番号
|
12
|
+
Version = "0.0.1"
|
13
|
+
|
14
|
+
# コマンドの実行
|
15
|
+
Twmerge::CLI.execute(STDOUT, ARGV)
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'parsedate'
|
4
|
+
|
5
|
+
class Tweet
|
6
|
+
attr_reader :time_stamp, :content
|
7
|
+
|
8
|
+
def initialize(time_stamp, content)
|
9
|
+
@time_stamp = time_stamp
|
10
|
+
@content = content
|
11
|
+
end
|
12
|
+
|
13
|
+
# テキストをつぶやき形式に整形する
|
14
|
+
def self.decorate(text)
|
15
|
+
array = text.split("\n")
|
16
|
+
|
17
|
+
array.each_with_index do |line, index|
|
18
|
+
# 5つ以上の水平線を4つにそろえる
|
19
|
+
array[index] = array[index].sub(/^----+$/, "----")
|
20
|
+
|
21
|
+
# 水平線手前の日付表示に装飾を付ける
|
22
|
+
if (line =~ /^----+$/ and index > 0)
|
23
|
+
ary = ParseDate::parsedate(array[index - 1])
|
24
|
+
if (ary[0]) # 日付表示の場合のみ
|
25
|
+
array[index - 1] = "~~@@color(gray):" + array[index - 1] + "@@~~"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
array.join("\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
# つぶやき形式のテキストをマージする
|
34
|
+
def self.merge(origin, add)
|
35
|
+
origin_t = Tweet.parse_from_text(origin)
|
36
|
+
add_t = Tweet.parse_from_text(add)
|
37
|
+
|
38
|
+
add_t.each do |tweet|
|
39
|
+
origin_t.insert(find_insert_pos(origin_t, tweet), tweet)
|
40
|
+
end
|
41
|
+
|
42
|
+
origin_t
|
43
|
+
end
|
44
|
+
|
45
|
+
# ソートされたつぶやきの配列に対して、あるつぶやきの挿入位置を返す
|
46
|
+
def self.find_insert_pos(tweets, tweet)
|
47
|
+
return 0 if tweet.time_stamp.nil?
|
48
|
+
|
49
|
+
tweets.each_index do |index|
|
50
|
+
if (tweets[index].time_stamp.nil?)
|
51
|
+
next
|
52
|
+
elsif (tweet.time_stamp >= tweets[index].time_stamp)
|
53
|
+
return index
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
return tweets.size
|
58
|
+
end
|
59
|
+
|
60
|
+
# つぶやき形式の文字列を渡すと、Tweet型の配列を返す
|
61
|
+
def self.parse_from_text(text)
|
62
|
+
tweets = []
|
63
|
+
array = text.split("\n")
|
64
|
+
|
65
|
+
index = 0
|
66
|
+
start_index = 0
|
67
|
+
is_pre = false
|
68
|
+
|
69
|
+
while true
|
70
|
+
if (array[index] =~ /^\{\{\{/)
|
71
|
+
is_pre = true
|
72
|
+
end
|
73
|
+
|
74
|
+
if (!is_pre and array[index] =~ /^----+/)
|
75
|
+
text = array[start_index...index].join("\n")
|
76
|
+
tweets.push Tweet.new(parse_time_stamp(text), text)
|
77
|
+
start_index = index + 1
|
78
|
+
end
|
79
|
+
|
80
|
+
if (array[index] =~ /^\}\}\}/)
|
81
|
+
is_pre = false
|
82
|
+
end
|
83
|
+
|
84
|
+
index += 1
|
85
|
+
|
86
|
+
if (index >= array.size)
|
87
|
+
if (index > start_index)
|
88
|
+
text = array[start_index..index].join("\n")
|
89
|
+
tweets.push Tweet.new(parse_time_stamp(text), text)
|
90
|
+
end
|
91
|
+
|
92
|
+
break
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
tweets
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.parse_time_stamp(text)
|
100
|
+
str = text.split(/\n/)[-1]
|
101
|
+
|
102
|
+
if (str)
|
103
|
+
ary = ParseDate::parsedate(str)
|
104
|
+
if (ary[0])
|
105
|
+
Time::local(*ary[0..4])
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
else
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/tidtools.rb
CHANGED
data/lib/twmerge/cli.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), '../tidtools/tiddle')
|
3
|
+
require File.join(File.dirname(__FILE__), '../tidtools/tweet')
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
module Twmerge
|
7
|
+
class CLI
|
8
|
+
def self.execute(stdout, arguments=[])
|
9
|
+
opt = OptionParser.new('twmerge origin_file add_file')
|
10
|
+
opt.parse!(arguments)
|
11
|
+
|
12
|
+
if (arguments.size != 2)
|
13
|
+
puts opt.help
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
# テキストを取得
|
18
|
+
origin = open(arguments[0]).read
|
19
|
+
add = Tweet.decorate(open(arguments[1]).read)
|
20
|
+
|
21
|
+
# マージ
|
22
|
+
tweets = Tweet.merge(origin, add)
|
23
|
+
|
24
|
+
# 結果を表示
|
25
|
+
tweets.each do |elem|
|
26
|
+
puts elem.content, "----"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- ongaeshi
|
@@ -65,6 +65,7 @@ email:
|
|
65
65
|
executables:
|
66
66
|
- tidgrep
|
67
67
|
- twgrep
|
68
|
+
- twmerge
|
68
69
|
extensions: []
|
69
70
|
|
70
71
|
extra_rdoc_files:
|
@@ -79,11 +80,14 @@ files:
|
|
79
80
|
- Rakefile
|
80
81
|
- bin/tidgrep
|
81
82
|
- bin/twgrep
|
83
|
+
- bin/twmerge
|
82
84
|
- lib/tidgrep/cli.rb
|
83
85
|
- lib/tidtools.rb
|
84
86
|
- lib/tidtools/platform.rb
|
85
87
|
- lib/tidtools/tiddle.rb
|
88
|
+
- lib/tidtools/tweet.rb
|
86
89
|
- lib/twgrep/cli.rb
|
90
|
+
- lib/twmerge/cli.rb
|
87
91
|
- script/console
|
88
92
|
- script/destroy
|
89
93
|
- script/generate
|
@@ -91,6 +95,7 @@ files:
|
|
91
95
|
- test/test_tidgrep_cli.rb
|
92
96
|
- test/test_tidtools.rb
|
93
97
|
- test/test_twgrep_cli.rb
|
98
|
+
- test/test_twmerge_cli.rb
|
94
99
|
has_rdoc: true
|
95
100
|
homepage: http://github.com/ongaeshi/tidtools
|
96
101
|
licenses: []
|