Class: Command::Flag
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::Flag
- Defined in:
- lib/command/flag.rb
Constant Summary collapse
- ATTRIBUTES =
%w(end)
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ Flag
constructor
A new instance of Flag.
- #oneline_help ⇒ Object
Methods inherited from CommandBase
execute_and_rescue_exit, #load_local_settings
Constructor Details
#initialize ⇒ Flag
Returns a new instance of Flag.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/command/flag.rb', line 18 def initialize super("<attribute> <target> [<target2> ...]") @opt.separator <<-EOS ・指定した小説に各種フラグを設定します ・再実行で解除 ・現在指定可能なフラグ end : 小説が完結状態かどうか Example: narou flag end 100 # ID:100の小説を完結状態にする EOS end |
Instance Method Details
#execute(argv) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/command/flag.rb', line 32 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"] || {} if flags.include?(attribute) flags.delete(attribute) puts "#{data['title']} から #{attribute} フラグを削除しました" else flags[attribute] = true 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 |