Class: Command::List
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::List
- Defined in:
- lib/command/list.rb
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #oneline_help ⇒ Object
- #output_list(novels) ⇒ Object
Methods inherited from CommandBase
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/command/list.rb', line 10 def initialize super("[<number>] [options]") @opt.separator <<-EOS ・現在管理している小説の一覧を表示します。 ・表示されるIDは各コマンドで指定することで小説名等を入力する手間を省けます。 ・個数を与えることで、最大表示数を制限できます(デフォルトは全て表示) Example: narou list # IDの小さい順に全て表示 narou list 10 -r # IDの大きい順に10件表示 narou list 5 -l # 最近更新のあった5件表示 narou list 10 -rl # 最新10件を古い順に表示 Options: EOS @opt.on("-l", "--latest", "最近更新のあった順に小説を表示する") { @options["latest"] = true } @opt.on("-r", "--reverse", "逆順に表示する") { @options["reverse"] = true } @opt.on("-u", "--url", "小説の掲載ページも表示する") { @options["url"] = true } end |
Instance Method Details
#execute(argv) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/command/list.rb', line 53 def execute(argv) super database_values = Database.instance.get_object.values if !argv.empty? && argv.first =~ /^\d+$/ num = argv.first.to_i else num = database_values.count end if @options["latest"] database_values = Database.instance.sort_by_last_update end database_values.reverse! if @options["reverse"] novels = database_values[0, num] output_list(novels) end |
#oneline_help ⇒ Object
69 70 71 |
# File 'lib/command/list.rb', line 69 def oneline_help "現在管理している小説の一覧を表示します" end |
#output_list(novels) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/command/list.rb', line 37 def output_list(novels) puts " ID | 更新日 | タイトル" novels.each do |novel| id = novel["id"] frozen = Narou.novel_frozen?(id) disp_id = ((frozen ? "*" : "") + id.to_s).rjust(4) disp_id = disp_id.sub("*", "<cyan>*</cyan>").termcolor if frozen puts [ disp_id, novel["last_update"].strftime("%y/%m/%d"), novel["title"], @options["url"] ? novel["toc_url"] : nil ].compact.join(" | ") end end |