Class: Command::Send
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::Send
- Defined in:
- lib/command/send.rb
Instance Method Summary collapse
- #execute(argv) ⇒ Object
- #get_device(argv) ⇒ Object
-
#initialize ⇒ Send
constructor
A new instance of Send.
- #oneline_help ⇒ Object
Methods inherited from CommandBase
Constructor Details
#initialize ⇒ Send
Returns a new instance of Send.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/command/send.rb', line 16 def initialize super("<device> [<target1> <target2> ...]") @opt.separator <<-EOS ・<target>で指定した小説の電子書籍データ(#{Device::DEVICES.map{|_,d| d::EBOOK_FILE_EXT}.join(", ")})を<device>で指定した端末に送信します。 <device>には現在 #{Device::DEVICES.keys.join(", ")} が指定出来ます。 ・narou setting device=<device>としておけば、<device>の入力を省略できます。 また、convertコマンドで変換時に(端末がPCに接続されていれば)自動でデータを送信するようになります。 ・<target>を省略した場合、管理している小説全てのファイルのタイムスタンプを端末のものと比べて新しければ送信します。 Example: narou send kindle 6 narou send kobo 6 # <device>の省略 narou setting device=kindle narou send 6 narou send # 端末のファイルより新しいファイルがあれば送信 EOS end |
Instance Method Details
#execute(argv) ⇒ Object
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/command/send.rb', line 45 def execute(argv) super device = get_device(argv) unless device error "デバイス名を指定して下さい" exit 1 end unless device.connecting? error "#{device.name}が接続されていません" exit 1 end send_all = false titles = {} if argv.empty? send_all = true Database.instance.each do |id, data| argv << id titles[id] = data["title"] end end argv.each do |target| ebook_path = Narou.get_ebook_file_path(target, device.ebook_file_ext) unless ebook_path error "#{target} は存在しません" next end unless File.exists?(ebook_path) error "まだファイル(#{File.basename(ebook_path)})が無いようです" unless send_all next end if send_all if device.ebook_file_old?(ebook_path) puts "<green>ID:#{target} #{TermColor.escape(titles[target])}</green>".termcolor else next end end print "#{device.name}へ送信しています" exit_copy = false copy_to_path = nil Thread.new do copy_to_path = device.copy_to_documents(ebook_path) exit_copy = true end until exit_copy print "." sleep(0.5) end if copy_to_path puts puts copy_to_path + " へコピーしました" else error "#{device.name}が見つからなかったためコピー出来ませんでした" exit 1 # next しても次も失敗すると分かりきっているためここで終了する end end end |
#get_device(argv) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/command/send.rb', line 38 def get_device(argv) if argv.first && Device.exists?(argv.first) return Narou.get_device(argv.shift) end Narou.get_device end |
#oneline_help ⇒ Object
12 13 14 |
# File 'lib/command/send.rb', line 12 def oneline_help "変換したEPUB/MOBIを電子書籍端末に送信します" end |