Class: TamTam::MessageSet
- Inherits:
-
Object
- Object
- TamTam::MessageSet
- Includes:
- Enumerable
- Defined in:
- lib/tam_tam/message_set.rb
Overview
A collection of messages. Responsible for filtering and manipulating messages.
Instance Attribute Summary collapse
-
#data ⇒ Object
writeonly
Sets the attribute data.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #by_count ⇒ Object
- #each ⇒ Object
- #including(phrase) ⇒ Object
-
#initialize(data) ⇒ MessageSet
constructor
A new instance of MessageSet.
- #matching(pattern) ⇒ Object
- #sent_by(sender) ⇒ Object
- #size ⇒ Object (also: #length)
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(data) ⇒ MessageSet
Returns a new instance of MessageSet.
12 13 14 |
# File 'lib/tam_tam/message_set.rb', line 12 def initialize(data) self.data = data.map { |data| Message.new(data) } end |
Instance Attribute Details
#data=(value) ⇒ Object
Sets the attribute data
9 10 11 |
# File 'lib/tam_tam/message_set.rb', line 9 def data=(value) @data = value end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 |
# File 'lib/tam_tam/message_set.rb', line 45 def ==(other) data == other.data end |
#by_count ⇒ Object
34 35 36 37 38 39 |
# File 'lib/tam_tam/message_set.rb', line 34 def by_count Hash[group_by { || .text }.inject({}) { |counts, groups| counts[groups[0]] = groups[1].size counts }.sort_by { |key, value| -value }] end |
#each ⇒ Object
41 42 43 |
# File 'lib/tam_tam/message_set.rb', line 41 def each data.each { || yield } end |
#including(phrase) ⇒ Object
16 17 18 19 20 |
# File 'lib/tam_tam/message_set.rb', line 16 def including(phrase) copy = dup copy.data = data.select { || .text.include?(phrase) } copy end |
#matching(pattern) ⇒ Object
22 23 24 25 26 |
# File 'lib/tam_tam/message_set.rb', line 22 def matching(pattern) copy = dup copy.data = data.select { || .text.match(pattern) } copy end |
#sent_by(sender) ⇒ Object
28 29 30 31 32 |
# File 'lib/tam_tam/message_set.rb', line 28 def sent_by(sender) copy = dup copy.data = data.select { || .sender == sender } copy end |
#size ⇒ Object Also known as: length
54 55 56 |
# File 'lib/tam_tam/message_set.rb', line 54 def size data.size end |
#to_s ⇒ Object Also known as: inspect
49 50 51 |
# File 'lib/tam_tam/message_set.rb', line 49 def to_s %{#<#{self.class.name}:0x#{object_id.to_s(16)} size=#{size}>} end |