Class: Pidgin2Adium::TextLogParser

Inherits:
BasicParser show all
Defined in:
lib/pidgin2adium/parsers/text_log_parser.rb

Constant Summary

Constants inherited from BasicParser

BasicParser::MINIMAL_TIME_REGEX, BasicParser::TIME_REGEX, BasicParser::TIME_REGEX_FIRST_LINE

Constants included from Pidgin2Adium

ADIUM_LOG_DIR, BAD_DIRS, FILE_EXISTS, VERSION

Instance Method Summary collapse

Methods inherited from BasicParser

#create_adium_time, #create_msg, #create_status_or_event_msg, #get_sender_by_alias, #is_minimal_time?, #parse, #pre_parse!, #strptime, #try_to_parse_minimal_time, #try_to_parse_time, #try_to_parse_time_with_formats

Methods included from Pidgin2Adium

balance_tags_c, delete_search_indexes, error, log_msg, oops, parse, parse_and_generate

Constructor Details

#initialize(src_path, user_aliases) ⇒ TextLogParser

Returns a new instance of TextLogParser.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pidgin2adium/parsers/text_log_parser.rb', line 6

def initialize(src_path, user_aliases)
  super(src_path, user_aliases)
  @timestamp_rx = '\((\d{1,2}:\d{1,2}:\d{1,2})\)'

  # @line_regex matches a line in a TXT log file other than the first
  # @line_regex matchdata:
  # 0: timestamp
  # 1: screen name or alias, if alias set
  # 2: "<AUTO-REPLY>" or nil
  # 3: message body
  @line_regex = /#{@timestamp_rx} (.*?) ?(<AUTO-REPLY>)?: (.*)/o
  # @line_regex_status matches a status line
  # @line_regex_status matchdata:
  # 0: timestamp
  # 1: status message
  @line_regex_status = /#{@timestamp_rx} ([^:]+)/o
end

Instance Method Details

#cleanup(text) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pidgin2adium/parsers/text_log_parser.rb', line 24

def cleanup(text)
  text.tr!("\r", '')
  # Escape entities since this will be in XML
  text.gsub!('&', '&amp;') # escape '&' first
  text.gsub!('<', '&lt;')
  text.gsub!('>', '&gt;')
  text.gsub!('"', '&quot;')
  text.gsub!("'", '&apos;')
  # Replace newlines with "<br/>" unless they end a chat line.
  # Add the <br/> after converting to &lt; etc so we
  # don't escape the tag.
  text.gsub!(/\n(?!(#{@timestamp_rx}|\Z))/, '<br/>')
  return text
end