Class: Hangout
- Inherits:
-
Cinch::Plugins::Hangouts
- Object
- Cinch::Plugins::Hangouts
- Hangout
- 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
-
#hangout_filename ⇒ Object
Returns the value of attribute hangout_filename.
-
#id ⇒ Object
Returns the value of attribute id.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#time ⇒ Object
Returns the value of attribute time.
Attributes inherited from Cinch::Plugins::Hangouts
Class Method Summary collapse
- .delete_expired(expire_time, files) ⇒ Object
- .find_by_id(id, files) ⇒ Object
- .listing(files) ⇒ Object
- .sorted(files) ⇒ Object
- .url(id, shorten = true) ⇒ Object
Instance Method Summary collapse
-
#initialize(nick, id, time, files) ⇒ Hangout
constructor
A new instance of Hangout.
- #save ⇒ Object
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_filename ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 4 def id @id end |
#nick ⇒ Object
Returns the value of attribute nick.
4 5 6 |
# File 'lib/cinch/plugins/hangouts/hangout.rb', line 4 def nick @nick end |
#time ⇒ Object
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
#save ⇒ Object
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 |