Class: Runoff::SkypeDataFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/runoff/skype_data_format.rb

Overview

Public: Deals with Skype specific formats.

Instance Method Summary collapse

Instance Method Details

#build_entry(chat_record) ⇒ Object

Public: Creates a String with one entry from the chat.

chat_record - a Hash containing data about a single chat message.

Examples

build_entry { timestamp: 213213232, from_dispname: 'aidzis', body_xml: 'This is text.' }
# => [2013-04-13 14:23:57] aidzis: This is text.

Returns a String with a chat entry.



28
29
30
31
32
33
34
35
# File 'lib/runoff/skype_data_format.rb', line 28

def build_entry(chat_record)
  datetime = Time.at chat_record[:timestamp]
  output_record = "[#{datetime.strftime "%Y-%m-%d %H:%M:%S"}] "
  output_record << "#{chat_record[:from_dispname]}: #{parse_body_xml chat_record[:body_xml]}"

  output_record
rescue StandardError
end

#get_filename(chat_record) ⇒ Object

Public: Builds an appropriate filename.

chat_record - A Hash containing necessary data.

Examples

get_filename { chatname: 'demo-chat' }
# => demo-chat.txt

Retruns a filename as a String.



14
15
16
# File 'lib/runoff/skype_data_format.rb', line 14

def get_filename(chat_record)
  "#{parse_chatname chat_record[:chatname]}.txt"
end

#parse_chatname(raw_chatname) ⇒ Object

Public: Converts chatname from database to a valid file name.

raw_chatname - A String with a chatname read from the database.

Examples

parse_chatname '#someone/$someone_else;521357125362'
# => someone-someone_else.txt

Returns a String with a valid file name.



47
48
49
50
51
52
53
# File 'lib/runoff/skype_data_format.rb', line 47

def parse_chatname(raw_chatname)
  match = raw_chatname.match(/#(.+)\/\$(.+);|#(.+)\/\$/)
  first_part, second_part, third_part = match.captures
  chatname = "#{first_part}-#{second_part}-#{third_part}"

  trim_dashes chatname
end

#partly_parse_chatname(raw_chatname) ⇒ Object

Public: Removes extra characters from the end of a chatname.

raw_chatname - A String with a chatname read from the database

Examples

partly_parse_chatname '#someone/$someone_else;521357125362'
# => #someone/$someone_else;

Returns a String with a chatname without extra characters at the end.



65
66
67
68
69
70
# File 'lib/runoff/skype_data_format.rb', line 65

def partly_parse_chatname(raw_chatname)
  match = raw_chatname.match(/(#.+\/\$.+;)|(#.+\/\$)/)
  first_group, second_group = match.captures

  first_group || second_group
end