Class: TamTam::Adapters::Adium

Inherits:
TamTam::Adapter show all
Defined in:
lib/tam_tam/adapters/adium.rb

Overview

Adapter for Adium. adium.im/

Instance Attribute Summary

Attributes inherited from TamTam::Adapter

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TamTam::Adapter

#initialize, #to_s

Constructor Details

This class inherits a constructor from TamTam::Adapter

Class Method Details

.default_pathObject



9
10
11
# File 'lib/tam_tam/adapters/adium.rb', line 9

def self.default_path
  "#{Dir.home}/Library/Application Support/Adium 2.0/Users/Default/Logs"
end

Instance Method Details

#as(accounts) ⇒ Object



32
33
34
# File 'lib/tam_tam/adapters/adium.rb', line 32

def as(accounts)
  Dir["#{path}/*\.{#{accounts.join(',')}}/**/*.xml"]
end

#between(start, stop) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/tam_tam/adapters/adium.rb', line 44

def between(start, stop)
  start = start.to_date
  stop = stop.to_date

  default_matches.select do |log|
    match = log.match(/(\d{4})-(\d{2})-(\d{2})/)
    log_date = Time.new(match[1], match[2], match[3]).to_date
    log_date >= start && log_date <= stop
  end
end

#default_matchesObject



13
14
15
# File 'lib/tam_tam/adapters/adium.rb', line 13

def default_matches
  Dir["#{path}/**/*.xml"]
end

#load_messages(matches) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tam_tam/adapters/adium.rb', line 17

def load_messages(matches)
  matches.map do |log_path|
    xml = File.read(log_path)
    doc = Nokogiri.parse(xml)

    doc.css("chat message").map do |message|
      {
        sender: message.attribute("sender").value,
        text: message.text,
        time: Chronic.parse(message.attribute("time").value)
      }
    end
  end.flatten
end

#on(start) ⇒ Object



40
41
42
# File 'lib/tam_tam/adapters/adium.rb', line 40

def on(start)
  Dir["#{path}/**/*#{start.to_date.to_s}*/*.xml"]
end

#with(participants) ⇒ Object



36
37
38
# File 'lib/tam_tam/adapters/adium.rb', line 36

def with(participants)
  Dir["#{path}/*\.*/{#{participants.join(',')}}/**/*.xml"]
end