tidtools 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -6,6 +6,7 @@ Rakefile
6
6
  bin/tidgrep
7
7
  lib/tidgrep/cli.rb
8
8
  lib/tidtools.rb
9
+ lib/tidtools/tiddle.rb
9
10
  script/console
10
11
  script/destroy
11
12
  script/generate
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = tidtools
2
2
 
3
- * http://github.com/#{github_username}/#{project_name}
3
+ * http://github.com/ongaeshi/tidtools
4
4
 
5
5
  == DESCRIPTION:
6
6
 
data/Rakefile CHANGED
@@ -14,8 +14,7 @@ $hoe = Hoe.spec 'tidtools' do
14
14
  self.developer 'ongaeshi', 'ongaeshi@example.com'
15
15
  self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
- # self.extra_deps = [['activesupport','>= 2.0.2']]
18
-
17
+ self.extra_deps = [['hpricot','>= 0.8.2']]
19
18
  end
20
19
 
21
20
  require 'newgem/tasks'
data/lib/tidtools.rb CHANGED
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Tidtools
5
- VERSION = '0.0.1'
6
- end
5
+ VERSION = '0.0.2'
6
+ end
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'hpricot'
5
+ require 'parsedate'
6
+
7
+ class Tiddle
8
+ attr_reader :title, :created, :modified, :tags, :changecount, :content
9
+
10
+ def initialize(title, created, modified, tags, changecount, content)
11
+ @title = title
12
+ @created = created
13
+ @modified = modified
14
+ @tags = tags
15
+ @changecount = changecount
16
+ @content = content
17
+ end
18
+
19
+ # TiddlyWikiのファイルを渡すと、Tiddleの配列を返す
20
+ def self.parse(file_name)
21
+ tiddles = []
22
+
23
+ doc = Hpricot(open(file_name).read())
24
+
25
+ doc.search("div").each do |elem|
26
+ if (elem['id'] == 'storeArea')
27
+ elem.search("div").each do |tiddle|
28
+ tiddles.push(Tiddle.new(title(tiddle),
29
+ convtime(tiddle['created']),
30
+ convtime(tiddle['modified']),
31
+ tiddle['tags'],
32
+ tiddle['changecount'],
33
+ content(tiddle)))
34
+
35
+ # print tiddle['modified'], '=>', tiddles.last.modified, "\n"
36
+ end
37
+ end
38
+ end
39
+
40
+ return tiddles
41
+ end
42
+
43
+ def self.parse_sort_modified(file_name)
44
+ parse(file_name).sort {|a, b|
45
+ if (b.modified.nil?)
46
+ -1
47
+ elsif (a.modified.nil?)
48
+ 1
49
+ else
50
+ a.modified <=> b.modified
51
+ end
52
+ }.reverse
53
+ end
54
+
55
+ # tiddleのタイトルを取得
56
+ def self.title(tiddle)
57
+ tiddle['title'] || tiddle['tiddler']
58
+ end
59
+
60
+ # tiddleの内容を取得
61
+ def self.content(tiddle)
62
+ pre = tiddle.search("pre")
63
+
64
+ if (pre.size > 0)
65
+ pre.inner_html
66
+ else
67
+ tiddle.inner_html
68
+ end
69
+ end
70
+
71
+ # 時刻に変換
72
+ def self.convtime(str)
73
+ if (str)
74
+ ary = ParseDate::parsedate(str)
75
+ Time::local(*ary[0..4])
76
+ else
77
+ nil
78
+ end
79
+ end
80
+ end
81
+
@@ -11,4 +11,4 @@ class TestTidgrepCli < Test::Unit::TestCase
11
11
  def test_print_default_output
12
12
  assert_match(/To update this executable/, @stdout)
13
13
  end
14
- end
14
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - ongaeshi
@@ -18,9 +18,23 @@ date: 2010-04-24 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rubyforge
21
+ name: hpricot
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 8
30
+ - 2
31
+ version: 0.8.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rubyforge
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - ">="
26
40
  - !ruby/object:Gem::Version
@@ -30,11 +44,11 @@ dependencies:
30
44
  - 4
31
45
  version: 2.0.4
32
46
  type: :development
33
- version_requirements: *id001
47
+ version_requirements: *id002
34
48
  - !ruby/object:Gem::Dependency
35
49
  name: hoe
36
50
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
51
+ requirement: &id003 !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - ">="
40
54
  - !ruby/object:Gem::Version
@@ -44,7 +58,7 @@ dependencies:
44
58
  - 0
45
59
  version: 2.6.0
46
60
  type: :development
47
- version_requirements: *id002
61
+ version_requirements: *id003
48
62
  description: FIX (describe your package)
49
63
  email:
50
64
  - ongaeshi@example.com
@@ -65,6 +79,7 @@ files:
65
79
  - bin/tidgrep
66
80
  - lib/tidgrep/cli.rb
67
81
  - lib/tidtools.rb
82
+ - lib/tidtools/tiddle.rb
68
83
  - script/console
69
84
  - script/destroy
70
85
  - script/generate
@@ -72,7 +87,7 @@ files:
72
87
  - test/test_tidgrep_cli.rb
73
88
  - test/test_tidtools.rb
74
89
  has_rdoc: true
75
- homepage: http://github.com/#{github_username}/#{project_name}
90
+ homepage: http://github.com/ongaeshi/tidtools
76
91
  licenses: []
77
92
 
78
93
  post_install_message: PostInstall.txt