Class: SkypeHistoryImport::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/skype-history-import.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nike_to_email_mappingObject

Returns the value of attribute nike_to_email_mapping.



6
7
8
# File 'lib/skype-history-import.rb', line 6

def nike_to_email_mapping
  @nike_to_email_mapping
end

Instance Method Details

#nike_to_email_map(nick, email) ⇒ Object



8
9
10
11
# File 'lib/skype-history-import.rb', line 8

def nike_to_email_map(nick, email)
	@nike_to_email_map = Hash.new if @nike_to_email_map.nil?
	@nike_to_email_map[nick] = email
end

#run(text) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/skype-history-import.rb', line 13

def run(text)
	result = []
	
	message = Message.new
	
	while text.strip.size > 0
		if text =~ /^\[(.+)\] (.+?): (.*)/
			
			# handle tail of prev multi line message
			unless $` == nil or message.text == nil or $`.strip == ""
				message.text += $`
			end
			
			# if date is only time, then found string is boby of prev message
			time = DateTime.strptime($1, "%H:%M:%S") rescue nil
			if time
				message.text += $&
			else
				# message start
				message = Message.new
				
				begin
					message.date = DateTime.strptime($1, "%d/%m/%Y %H:%M:%S")
					message.nick = $2
					message.text = $3
					
					if @nike_to_email_map.nil? == false && @nike_to_email_map.has_key?(message.nick)
						message.email = @nike_to_email_map[message.nick]
					end
					
				rescue
					puts "Exception '#{$!}' on match *** #{$~} ***"
					raise
				end
				
				result.push(message)
			end
			
		end
		
		text = $'
	end

	result
end