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 "\n \u30FB\u73FE\u5728\u7BA1\u7406\u3057\u3066\u3044\u308B\u5C0F\u8AAC\u306E\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\n \u30FB\u8868\u793A\u3055\u308C\u308BID\u306F\u5404\u30B3\u30DE\u30F3\u30C9\u3067\u6307\u5B9A\u3059\u308B\u3053\u3068\u3067\u5C0F\u8AAC\u540D\u7B49\u3092\u5165\u529B\u3059\u308B\u624B\u9593\u3092\u7701\u3051\u307E\u3059\u3002\n \u30FB\u500B\u6570\u3092\u4E0E\u3048\u308B\u3053\u3068\u3067\u3001\u6700\u5927\u8868\u793A\u6570\u3092\u5236\u9650\u3067\u304D\u307E\u3059(\u30C7\u30D5\u30A9\u30EB\u30C8\u306F\u5168\u3066\u8868\u793A)\n\n Example:\nnarou list # ID\u306E\u5C0F\u3055\u3044\u9806\u306B\u5168\u3066\u8868\u793A\nnarou list 10 -r # ID\u306E\u5927\u304D\u3044\u9806\u306B10\u4EF6\u8868\u793A\nnarou list 5 -l # \u6700\u8FD1\u66F4\u65B0\u306E\u3042\u3063\u305F5\u4EF6\u8868\u793A\nnarou list 10 -rl # \u6700\u65B010\u4EF6\u3092\u53E4\u3044\u9806\u306B\u8868\u793A\n\n Options:\n EOS\n @opt.on(\"-l\", \"--latest\", \"\u6700\u8FD1\u66F4\u65B0\u306E\u3042\u3063\u305F\u9806\u306B\u5C0F\u8AAC\u3092\u8868\u793A\u3059\u308B\") {\n @options[\"latest\"] = true\n }\n @opt.on(\"-r\", \"--reverse\", \"\u9006\u9806\u306B\u8868\u793A\u3059\u308B\") {\n @options[\"reverse\"] = true\n }\n @opt.on(\"-u\", \"--url\", \"\u5C0F\u8AAC\u306E\u63B2\u8F09\u30DA\u30FC\u30B8\u3082\u8868\u793A\u3059\u308B\") {\n @options[\"url\"] = true\n }\nend\n" |
Instance Method Details
#execute(argv) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/command/list.rb', line 60 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 ["latest"] database_values = Database.instance.sort_by_last_update end database_values.reverse! if ["reverse"] novels = database_values[0, num] output_list(novels) end |
#oneline_help ⇒ Object
76 77 78 |
# File 'lib/command/list.rb', line 76 def oneline_help "現在管理している小説の一覧を表示します" end |
#output_list(novels) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/command/list.rb', line 37 def output_list(novels) today = Time.now.strftime("%y/%m/%d") 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").tap { |s| if novel["new_arrivals_date"] && novel["new_arrivals_date"].strftime("%y/%m/%d") == today s.replace "<bold><magenta>#{s}</magenta></bold>".termcolor elsif s == today s.replace "<bold><green>#{s}</green></bold>".termcolor end }, novel["title"], ["url"] ? novel["toc_url"] : nil ].compact.join(" | ") end end |