lib/Charu/ChangeLogMemo.rb in Charu-0.0.4 vs lib/Charu/ChangeLogMemo.rb in Charu-0.0.6
- old
+ new
@@ -1,51 +1,72 @@
# -*- encoding: utf-8 -*-
module Charu
- class Cotegory
- def initialize(title)
- if title == nil then
- title = ""
- end
+ class Category
+ attr_accessor :category
+ def initialize()
@category = []
- title.scan(/\[(.*?)\]:/).each{|i|
- self.add(i)
- }
+ @config = Charu::Config.new()
+
+ # プライベートの設定
+ @private_category = true
end
- def add(category)
- if category == nil then
- category = []
+ def add(title_source)
+ if title_source == nil then
+ title_source = ""
end
- category.each{|i|
- @category << i
+
+ title_source.scan(/\[(.*?)\]:/).each{|category|
+ @category << category[0]
}
end
def get_category_list()
@category.uniq! # 重複削除
return @category
end
+
+ def get_private_category()
+ # プライベートの設定
+ @category.each{|category|
+ @config.private_category.each{|private_category|
+ if category == private_category then
+ @private_category = false
+ end
+ }
+ }
+ return @private_category
+ end
end
class Item
- attr_accessor :datetime, :item_title_source, :item_log, :cotegory
- def initialize(time)
- if time == nil then
+ attr_accessor :date, :item_title_source, :item_log, :category
+ def initialize(date)
+ if date == nil then
p "アイテム初期化失敗"
- time = Time.now
+ date = Time.now
title = "アイテム初期化失敗"
end
- @datetime = time
+ @date = date
@item_title_source = title
@item_log = ""
# カテゴリー
+ @item_private_list = []
+
+ @category = Charu::Category.new()
+
end
+ def set_item_title_source(item_title_source)
+ @item_title_source = item_title_source
+ @category.add(@item_title_source)
+ end
+
def get_item_title()
if @item_title_source != nil then
i = @item_title_source.gsub(/\*\s/, "") # タイトルから[*]削除
i = i.gsub(/\[(.*?)\]:/, "") # タイトルからカテゴリ削除
@@ -69,45 +90,54 @@
if line != "" or line != "\n" then
@item_log = @item_log + "\n" + line
end
end
+ # カテゴリーリスト
def get_item_category()
- @cotegory = Cotegory.new(@item_title_source)
- if @cotegory == nil then
+ if @category == nil then
return []
end
- return @cotegory.get_category_list()
+ return @category.get_category_list()
end
+
+ # プライベートのフラグを返す
+ def get_private_category()
+ return @category.get_private_category
+ end
+
+ def get_item_date_string()
+ return @date.strftime("%Y-%m-%d")
+ end
+
end
class Entry
- attr_accessor :datetime, :item_title, :item_log, :cotegory
+ attr_accessor :date, :item_title, :item_log, :category, :item_source_date
def initialize(item_source)
- @item_source_day = ""
+ @item_source_date = ""
@item_source_contents = ""
- @item_source_day = item_source[0] # 時間データ・ソース
+ @item_source_date = item_source[0] # 時間データ・ソース
@item_source_contents = item_source[1] # 内容データ
if @item_source_contents == nil then
@item_source_contents == ""
end
end
def get_items() # 解析する
-
@items = []
item = nil
# 一行づつ処理する
@item_source_contents.split("\n").each{|line|
if item == nil then
- item = Item.new(@item_source_day)
+ item = Charu::Item.new(self.get_entry_time())
end
if line.match(/^\*\s.*?/) != nil or line.match(/^\t\*\s.*?/) != nil then
- item = Item.new(@item_source_day)
+ item = Charu::Item.new(self.get_entry_time())
@items << item
- item.item_title_source = line
+ item.set_item_title_source(line)
else
if line == nil then
line = ""
end
item.app_item_log(line)
@@ -143,14 +173,14 @@
=end
return @items
end
- def get_entry_time() #@entry_datetime = Time.mktime($1.to_i, $2.to_i, $3.to_i)
+ def get_entry_time() #@entry_date = Time.mktime($1.to_i, $2.to_i, $3.to_i)
t = Time.now
begin
- t = Time.mktime(@item_source_day.split(/-/)[0].to_i, @item_source_day.split(/-/)[1].to_i, @item_source_day.split(/-/)[2].to_i)
+ t = Time.mktime(@item_source_date.split(/-/)[0].to_i, @item_source_date.split(/-/)[1].to_i, @item_source_date.split(/-/)[2].to_i)
rescue
p "日付変換エラー".encode(Encoding::SJIS)
end
return t
end
@@ -173,103 +203,146 @@
entry_data = [entry_sources_split[i], entry_sources_split[s]]
# エントリー日付 # エントリー内容
i = i + 2
s = s + 2
if entry_data[1] != nil then
- entry = Entry.new(entry_data)
+ entry = Charu::Entry.new(entry_data)
@entrys << entry
end
end
end
+ end
+end
- def get_category_list()
- p "リスト".encode(Encoding::SJIS)
- category_list = []
+# プライベートと分ける
+module Charu
+ class ChangeLogPrivate < ChangeLog
+ def get_item_private()
+ @item_list_private = Hash.new()
+
@entrys.each{|entry|
entry.get_items().each{|item|
- item.get_item_category().each{|category|
- category_list << category.get_category()
- }
+ if item.get_private_category == true then
+ @item_list_private[item.get_item_date_string()] = [item]
+ end
}
}
- category_list.uniq!
- category_list.sort!{|a, b| a <=> b } # 並び替え
- category_list.delete("")
-
- return category_list
+ return @item_list_private
end
end
- class ChangeLogPrivate < ChangeLog
-
- end
-
class ChangeLogPublic < ChangeLog
-
+ def get_item_private()
+ @item_list_private = []
+ @entrys.entrys.each{|entry|
+ entry.get_items().each{|item|
+ @item_list_private << item
+ }
+ }
+ return @item_list_private
+ end
end
+end
+module Charu
class ChangeLogMemo
- attr_accessor :file_name
- def initialize(file_name)
- @file_name = file_name
+ def initialize()
+ @config = Charu::Config.new()
# ChangeLogMemoファイル
- File.open(@file_name, 'r:utf-8'){|f|
+ File.open(@config.change_log_path, 'r:utf-8'){|f|
@source = f.read # 全て読み込む
}
- @change_log_private = ChangeLogPrivate.new(@source)
+ @change_log_private = Charu::ChangeLogPrivate.new(@source)
-=begin
- @change_log_private.entrys.each{|date|
- date.get_items().each{|item|
- p "======="
- p date.get_items().size
- p item.datetime
- p item.get_item_title().encode(Encoding::SJIS)
- p item.get_item_log().encode(Encoding::SJIS)
- #p item
+ @item_list = @change_log_private.get_item_private()
+
+ # 全てのカテゴリーを取得
+ @all_category_list = []
+ @item_list.each{|key, items|
+ items.each{|item|
+ item.get_item_category().each{|category|
+ @all_category_list << category
+ }
}
}
-=end
end
- def get_item_sort()
- i = []
- @change_log_private.entrys.each{|date|
- date.get_items().each{|item|
- i << item
+ # アイテム数
+ def article_size_()
+ return @item_list.size()
+ end
- i.sort!{|a, b| a.datetime <=> b.datetime }
+ # ページ数
+ def article_size_max()
+ return @item_list.size() / @config.article_size
+ end
+
+
+ # アイテム数を50個とかで取り出せる
+ def article_size(item_list, cnt)
+ # [000-049] cnt 1 (1-1)*50 1*50-1
+ # [050-099] cnt 2 (2-1)*50 2*50-1
+ # [100-149] cnt 3 (3-1)*50 3*50-1
+
+ # ハッシュから配列に変換
+ items = []
+ item_list.each{|key, item|
+ items << item
+ }
+
+ # 配列で処理
+ i = [0, 0]
+ i[0] = (cnt - 1) * @config.article_size
+ i[1] = (cnt * @config.article_size) - 1
+
+ s = i[0]
+ t = []
+ while items[s] != nil and s <= i[1] do
+ t << items[s]
+ s = s + 1
+ end
+
+ # 配列からハッシュに変換
+ item_hash = Hash.new()
+ t.each{|items|
+ items.each{|item|
+ item_hash[item.get_item_date_string()] = [item]
}
}
- return i
+
+ return item_hash
end
- def get_item_sort_reverse()
- i = []
- @change_log_private.entrys.each{|date|
- date.get_items().each{|item|
- i << item
+ # 並び替え
+ def get_item_sort(cnt)
+ return article_size( Hash[ @item_list.sort ], cnt)
+ end
- i.sort!{|a, b| b.datetime <=> a.datetime }
- }
+ # 逆順で並び替え
+ def get_item_sort_reverse(cnt)
+ return article_size( Hash[ @item_list.sort.reverse ], cnt)
+ end
+
+ # カテゴリーのカテゴリー数をハッシュで戻す
+ def get_category_cnt()
+ category_cnt = Hash.new()
+
+ uniq_category_list = [] # 重複削除すみ
+ uniq_category_list = self.get_category_list()
+
+ uniq_category_list.each{|uniq_category|
+ category_cnt[uniq_category] = @all_category_list.count(uniq_category)
}
- return i
+
+ return Hash[ category_cnt.sort ]
end
+ # カテゴリーを取得する
def get_category_list()
- category_list = []
- @change_log_private.entrys.each{|date|
- date.get_items().each{|item|
- item.get_item_category().each{|category|
- category_list << category
- }
- }
- }
- category_list.uniq!
- return category_list
+ return @all_category_list.uniq()
end
end
end