Class: VimSwapFile
- Inherits:
-
Object
- Object
- VimSwapFile
- Defined in:
- lib/vim-swap.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#swapname ⇒ Object
readonly
Returns the value of attribute swapname.
Instance Method Summary collapse
- #get_body(body) ⇒ Object
-
#initialize(swapname, body) ⇒ VimSwapFile
constructor
A new instance of VimSwapFile.
- #running? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(swapname, body) ⇒ VimSwapFile
Returns a new instance of VimSwapFile.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vim-swap.rb', line 9 def initialize(swapname, body) if !VimVersion.matches("7.1") raise("This class requires Vim 7.1") end swapname =~ /^(\d+)\. +(.*)$/ @id = $1 @swapname = $2.strip get_body(body) end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/vim-swap.rb', line 7 def filename @filename end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/vim-swap.rb', line 7 def id @id end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
7 8 9 |
# File 'lib/vim-swap.rb', line 7 def pid @pid end |
#swapname ⇒ Object (readonly)
Returns the value of attribute swapname.
7 8 9 |
# File 'lib/vim-swap.rb', line 7 def swapname @swapname end |
Instance Method Details
#get_body(body) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vim-swap.rb', line 20 def get_body(body) fields = {} body.split(/\r/).each do |line| line =~ /^ +(.+): (.+)$/ fields[$1] = $2 end @filename = fields["file name"] @pid = fields["process ID"] @running = false if @pid =~ /\(still running\)$/ @pid = @pid.split(" ")[0] @running = true end end |
#running? ⇒ Boolean
35 36 37 |
# File 'lib/vim-swap.rb', line 35 def running? @running end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/vim-swap.rb', line 39 def to_s "id: #{@id}\nswapname: #{@swapname}\nfilename: #{@filename}\npid: #{@pid}\nrunning: #{@running}" end |