Class: Charu::ChangeLogMemo

Inherits:
Object
  • Object
show all
Defined in:
lib/Charu/ChangeLogMemo.rb

Instance Method Summary collapse

Constructor Details

#initializeChangeLogMemo

Returns a new instance of ChangeLogMemo.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/Charu/ChangeLogMemo.rb', line 260

def initialize()
  @config = Charu::Config.new()

  # ChangeLogMemoファイル
  File.open(@config.change_log_path, 'r:utf-8'){|f|
    @source = f.read  # 全て読み込む
  }

  @change_log_private = Charu::ChangeLogPrivate.new(@source)

  @item_list = @change_log_private.get_item_private()

  # 全てのカテゴリーを取得
  @all_category_list = []
  @item_list.each{|key, items|
    #p "key " + key
    #p items
    items.each{|item|
      item.get_item_category().each{|category|
        @all_category_list << category
      }
    }
  }
end

Instance Method Details

#article_size(item_list, cnt) ⇒ Object

アイテム数を50個とかで取り出せる



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/Charu/ChangeLogMemo.rb', line 296

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|
    item_hash[items.first.get_item_date_string()] = items
  }
  return item_hash
end

#article_size_Object

アイテム数



286
287
288
# File 'lib/Charu/ChangeLogMemo.rb', line 286

def article_size_()
  return @item_list.size()
end

#article_size_maxObject

ページ数



291
292
293
# File 'lib/Charu/ChangeLogMemo.rb', line 291

def article_size_max()
  return @item_list.size() / @config.article_size
end

#get_category_cntObject

カテゴリーのカテゴリー数をハッシュで戻す



338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/Charu/ChangeLogMemo.rb', line 338

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 Hash[ category_cnt.sort ]
end

#get_category_listObject

カテゴリーを取得する



352
353
354
# File 'lib/Charu/ChangeLogMemo.rb', line 352

def get_category_list()
  return @all_category_list.uniq()
end

#get_item_sort(cnt) ⇒ Object

並び替え



328
329
330
# File 'lib/Charu/ChangeLogMemo.rb', line 328

def get_item_sort(cnt)
  return article_size( Hash[ @item_list.sort ], cnt)
end

#get_item_sort_reverse(cnt) ⇒ Object

逆順で並び替え



333
334
335
# File 'lib/Charu/ChangeLogMemo.rb', line 333

def get_item_sort_reverse(cnt)
  return article_size( Hash[ @item_list.sort.reverse ], cnt)
end