Class: VimSwapFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vim-swap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/vim-swap.rb', line 7

def filename
  @filename
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/vim-swap.rb', line 7

def id
  @id
end

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/vim-swap.rb', line 7

def pid
  @pid
end

#swapnameObject (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/vim-swap.rb', line 35

def running?
	@running
end

#to_sObject



39
40
41
# File 'lib/vim-swap.rb', line 39

def to_s
	"id: #{@id}\nswapname: #{@swapname}\nfilename: #{@filename}\npid: #{@pid}\nrunning: #{@running}"	
end