Class: Tiddle
- Inherits:
-
Object
- Object
- Tiddle
- Defined in:
- lib/tidtools/tiddle.rb
Instance Attribute Summary collapse
-
#changecount ⇒ Object
readonly
Returns the value of attribute changecount.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#modified ⇒ Object
readonly
Returns the value of attribute modified.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.content(tiddle) ⇒ Object
tiddleの内容を取得.
-
.convtime(str) ⇒ Object
時刻に変換 1.9の場合はDateTimeを、1.8.7の場合はTimeを返す.
-
.parse(file_name) ⇒ Object
TiddlyWikiのファイルを渡すと、Tiddleの配列を返す.
- .parse_sort_modified(file_name) ⇒ Object
-
.title(tiddle) ⇒ Object
tiddleのタイトルを取得.
Instance Method Summary collapse
-
#initialize(title, created, modified, tags, changecount, content) ⇒ Tiddle
constructor
A new instance of Tiddle.
Constructor Details
#initialize(title, created, modified, tags, changecount, content) ⇒ Tiddle
Returns a new instance of Tiddle.
15 16 17 18 19 20 21 22 |
# File 'lib/tidtools/tiddle.rb', line 15 def initialize(title, created, modified, , changecount, content) @title = title @created = created @modified = modified @tags = @changecount = changecount @content = content end |
Instance Attribute Details
#changecount ⇒ Object (readonly)
Returns the value of attribute changecount.
13 14 15 |
# File 'lib/tidtools/tiddle.rb', line 13 def changecount @changecount end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
13 14 15 |
# File 'lib/tidtools/tiddle.rb', line 13 def content @content end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
13 14 15 |
# File 'lib/tidtools/tiddle.rb', line 13 def created @created end |
#modified ⇒ Object (readonly)
Returns the value of attribute modified.
13 14 15 |
# File 'lib/tidtools/tiddle.rb', line 13 def modified @modified end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
13 14 15 |
# File 'lib/tidtools/tiddle.rb', line 13 def @tags end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
13 14 15 |
# File 'lib/tidtools/tiddle.rb', line 13 def title @title end |
Class Method Details
.content(tiddle) ⇒ Object
tiddleの内容を取得
66 67 68 69 70 |
# File 'lib/tidtools/tiddle.rb', line 66 def self.content(tiddle) data = content1(tiddle) data.gsub!(/\\n/, "\n") data end |
.convtime(str) ⇒ Object
時刻に変換
1.9の場合はDateTimeを、1.8.7の場合はTimeを返す
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/tidtools/tiddle.rb', line 86 def self.convtime(str) if (str) if Platform.ruby19? DateTime.parse(str) else ary = ParseDate::parsedate(str) Time::local(*ary[0..4]) end else nil end end |
.parse(file_name) ⇒ Object
TiddlyWikiのファイルを渡すと、Tiddleの配列を返す
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tidtools/tiddle.rb', line 25 def self.parse(file_name) tiddles = [] doc = Hpricot(open(file_name).read()) doc.search("div").each do |elem| if (elem['id'] == 'storeArea') elem.search("div").each do |tiddle| tiddles.push(Tiddle.new(title(tiddle), convtime(tiddle['created']), convtime(tiddle['modified']), tiddle['tags'], tiddle['changecount'], content(tiddle))) # print tiddle['modified'], '=>', tiddles.last.modified, "\n" end end end return tiddles end |
.parse_sort_modified(file_name) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tidtools/tiddle.rb', line 48 def self.parse_sort_modified(file_name) parse(file_name).sort {|a, b| if (b.modified.nil?) -1 elsif (a.modified.nil?) 1 else a.modified <=> b.modified end }.reverse end |
.title(tiddle) ⇒ Object
tiddleのタイトルを取得
61 62 63 |
# File 'lib/tidtools/tiddle.rb', line 61 def self.title(tiddle) tiddle['title'] || tiddle['tiddler'] end |