Module: Needy

Defined in:
lib/needy.rb

Defined Under Namespace

Classes: Git, IChat, IMAP

Constant Summary collapse

@@when =
{}
@@threads =
[]

Instance Method Summary collapse

Instance Method Details

#feed(abbrev, url) ⇒ Object



23
24
25
26
27
28
# File 'lib/needy.rb', line 23

def feed abbrev, url
  thr do
    feed = FeedTools::Feed.open(url)
    set abbrev, feed.updated || feed.items.map(&:published).max
  end
end

#git(abbrev, dir, branch, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/needy.rb', line 30

def git abbrev, dir, branch, &block
  thr do
    g = Needy::Git.new(dir, branch)
    yield(g) if block
    set abbrev, g.when
  end
end

#gmail(args, &block) ⇒ Object



17
18
19
20
21
# File 'lib/needy.rb', line 17

def gmail args, &block
  self.imap_server 'imap.gmail.com', { :port => 993,
                                       :ssl  => true,
                                       :folder => '[Gmail]/Sent Mail' }.merge(args), &block
end

#ichats(dir = "#{ENV['HOME']}/Documents/iChats") {|i| ... } ⇒ Object

Yields:

  • (i)


52
53
54
55
# File 'lib/needy.rb', line 52

def ichats dir = "#{ENV['HOME']}/Documents/iChats"
  i = Needy::IChat.new(dir, self)
  yield(i)
end

#imap_server(host, args) ⇒ Object



12
13
14
15
# File 'lib/needy.rb', line 12

def imap_server host, args
  i = Needy::IMAP.new(self, host, args)
  thr { yield(i) }
end

#set(abbrev, val) ⇒ Object



48
49
50
# File 'lib/needy.rb', line 48

def set abbrev, val
  @@when[abbrev.to_s] = val unless (@@when[abbrev.to_s] and @@when[abbrev.to_s] > val)
end

#thr(&block) ⇒ Object



44
45
46
# File 'lib/needy.rb', line 44

def thr &block
  @@threads.push(Thread.new(&block))
end

#whensObject



38
39
40
41
42
# File 'lib/needy.rb', line 38

def whens
  @@threads.each{|t| t.join}
  @@threads = []
  @@when
end