Class: Command::Flag
Constant Summary
collapse
- ATTRIBUTES =
%w(end delete)
Instance Method Summary
collapse
Methods inherited from CommandBase
execute!, #load_local_settings
Constructor Details
#initialize ⇒ Flag
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/command/flag.rb', line 18
def initialize
super("<attribute> <target> [<target2> ...]")
@opt.separator "\n \u30FB\u6307\u5B9A\u3057\u305F\u5C0F\u8AAC\u306B\u5404\u7A2E\u30D5\u30E9\u30B0\u3092\u8A2D\u5B9A\u3057\u307E\u3059\n \u30FB\u518D\u5B9F\u884C\u3067\u89E3\u9664\n \u30FB--on, --off \u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u4ED8\u3051\u308B\u3053\u3068\u3067\u5F37\u5236\u8A2D\u5B9A\u53EF\u80FD\n \u30FB\u73FE\u5728\u6307\u5B9A\u53EF\u80FD\u306A\u30D5\u30E9\u30B0\n end : \u5C0F\u8AAC\u304C\u5B8C\u7D50\u72B6\u614B\n delete: \u524A\u9664\u3055\u308C\u305F\u72B6\u614B\n\n Example:\nnarou flag end 100 # ID:100\u306E\u5C0F\u8AAC\u3092\u5B8C\u7D50\u72B6\u614B\u306B\u3059\u308B\nnarou flag end --on # \u73FE\u5728\u306E\u72B6\u614B\u306B\u95A2\u308F\u3089\u305A\u5B8C\u7D50\u72B6\u614B\u306B\u3059\u308B\n\n Options:\n EOS\n @opt.on(\"--on\", \"\u5F37\u5236\u7684\u306B\u30D5\u30E9\u30B0\u3092\u7ACB\u3066\u308B\") {\n @options[\"on\"] = true\n }\n @opt.on(\"--off\", \"\u5F37\u5236\u7684\u306B\u30D5\u30E9\u30B0\u3092\u306F\u305A\u3059\") {\n @options[\"off\"] = true\n }\nend\n"
|
Instance Method Details
#execute(argv) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/command/flag.rb', line 43
def execute(argv)
super
if argv.empty?
puts @opt.help
return
end
attribute = (argv.shift || "").downcase
unless ATTRIBUTES.include?(attribute)
error "有効なフラグを指定して下さい\n指定可能なフラグ:#{ATTRIBUTES.join(', ')}"
exit 1
end
if argv.length < 1
error "対象小説を指定して下さい"
exit 1
end
database = Database.instance
argv.each do |target|
data = Downloader.get_data_by_target(target)
unless data
error "#{target} は存在しません"
next
end
flags = data["flags"] || {}
flag = !flags[attribute]
flag = true if @options["on"]
flag = false if @options["off"]
flags[attribute] = flag
if flag
puts "#{data['title']} の #{attribute} フラグを立てました"
else
flags.delete(attribute)
puts "#{data['title']} から #{attribute} フラグをはずしました"
end
database[data["id"]]["flags"] = flags
end
database.save_database
end
|
#oneline_help ⇒ Object
14
15
16
|
# File 'lib/command/flag.rb', line 14
def oneline_help
"小説の各種フラグを設定します"
end
|