Class: Hangout

Inherits:
Cinch::Plugins::Hangouts show all
Defined in:
lib/cinch/plugins/hangouts/hangout.rb

Overview

Class to manage Hangout information

Constant Summary

Constants inherited from Cinch::Plugins::Hangouts

Cinch::Plugins::Hangouts::HANGOUTS_REGEX, Cinch::Plugins::Hangouts::HANGOUT_FILENAME, Cinch::Plugins::Hangouts::SUBSCRIPTION_FILENAME, Cinch::Plugins::Hangouts::VERSION

Instance Attribute Summary collapse

Attributes inherited from Cinch::Plugins::Hangouts

#storage

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cinch::Plugins::Hangouts

#list_hangouts, #listen, #process_hangout, #subscribe, #unsubscribe

Constructor Details

#initialize(nick, id, time, files) ⇒ Hangout

Returns a new instance of Hangout.



6
7
8
9
10
11
12
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 6

def initialize(nick, id, time, files)
  @nick = nick
  @id = id
  @time = time
  fail if files.nil? || !files.key?(:hangouts) || files[:hangouts].empty?
  @filename = files[:hangouts]
end

Instance Attribute Details

#hangout_filenameObject

Returns the value of attribute hangout_filename.



4
5
6
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 4

def hangout_filename
  @hangout_filename
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 4

def id
  @id
end

#nickObject

Returns the value of attribute nick.



4
5
6
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 4

def nick
  @nick
end

#timeObject

Returns the value of attribute time.



4
5
6
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 4

def time
  @time
end

Class Method Details

.delete_expired(expire_time, files) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 25

def self.delete_expired(expire_time, files)
  return if listing(files).nil?
  storage = read_file(files)
  storage.data[:hangouts].delete_if do |id, hangout|
    (Time.now - hangout.time) > (expire_time * 60)
  end
  storage.save
end

.find_by_id(id, files) ⇒ Object



21
22
23
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 21

def self.find_by_id(id, files)
  listing(files)[id]
end

.listing(files) ⇒ Object



40
41
42
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 40

def self.listing(files)
  read_file(files).data[:hangouts]
end

.sorted(files) ⇒ Object



34
35
36
37
38
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 34

def self.sorted(files)
  hangouts = listing(files).values
  hangouts.sort! { |x, y| y.time <=> x.time }
  hangouts
end

.url(id, shorten = true) ⇒ Object



44
45
46
47
48
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 44

def self.url(id, shorten = true)
  url = "https://plus.google.com/hangouts/_/#{id}"
  return url unless shorten
  Cinch::Toolbox.shorten(url)
end

Instance Method Details

#saveObject



14
15
16
17
18
19
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 14

def save
  storage = Cinch::Storage.new(@filename)
  storage.data[:hangouts] ||= {}
  storage.data[:hangouts][id] = self
  storage.save
end