Class: Whatsapp::Group
- Inherits:
-
Object
- Object
- Whatsapp::Group
- Defined in:
- lib/whatsapp/group.rb
Overview
Represents a WhatsApp group.
Instance Attribute Summary collapse
-
#creation ⇒ Integer?
readonly
Creation timestamp.
-
#description ⇒ String?
readonly
Group description.
-
#id ⇒ String
readonly
Group JID (e.g. "120363001234567890@g.us").
-
#owner ⇒ String?
readonly
Group owner JID.
-
#participants ⇒ Array<Hash>?
readonly
Participants list (+[{ id:, admin: }]+).
-
#raw ⇒ Hash
readonly
Raw data from the bridge.
-
#size ⇒ Integer
readonly
Number of participants.
-
#subject ⇒ String
readonly
Group subject (name).
Instance Method Summary collapse
-
#admins ⇒ Array<String>
List of admin participant JIDs.
-
#initialize(data) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
-
#participant_ids ⇒ Array<String>
List of all participant JIDs.
-
#to_h ⇒ Hash
Serialized group info.
Constructor Details
#initialize(data) ⇒ Group
Returns a new instance of Group.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/whatsapp/group.rb', line 35 def initialize(data) @raw = data @id = data[:id] @subject = data[:subject] @description = data[:description] @owner = data[:owner] @creation = data[:creation] @size = data[:size] || 0 @participants = data[:participants] end |
Instance Attribute Details
#creation ⇒ Integer? (readonly)
Returns creation timestamp.
23 24 25 |
# File 'lib/whatsapp/group.rb', line 23 def creation @creation end |
#description ⇒ String? (readonly)
Returns group description.
17 18 19 |
# File 'lib/whatsapp/group.rb', line 17 def description @description end |
#id ⇒ String (readonly)
Returns group JID (e.g. "120363001234567890@g.us").
11 12 13 |
# File 'lib/whatsapp/group.rb', line 11 def id @id end |
#owner ⇒ String? (readonly)
Returns group owner JID.
20 21 22 |
# File 'lib/whatsapp/group.rb', line 20 def owner @owner end |
#participants ⇒ Array<Hash>? (readonly)
Returns participants list (+[{ id:, admin: }]+).
29 30 31 |
# File 'lib/whatsapp/group.rb', line 29 def participants @participants end |
#raw ⇒ Hash (readonly)
Returns raw data from the bridge.
32 33 34 |
# File 'lib/whatsapp/group.rb', line 32 def raw @raw end |
#size ⇒ Integer (readonly)
Returns number of participants.
26 27 28 |
# File 'lib/whatsapp/group.rb', line 26 def size @size end |
#subject ⇒ String (readonly)
Returns group subject (name).
14 15 16 |
# File 'lib/whatsapp/group.rb', line 14 def subject @subject end |
Instance Method Details
#admins ⇒ Array<String>
List of admin participant JIDs.
49 50 51 52 53 54 55 |
# File 'lib/whatsapp/group.rb', line 49 def admins return [] unless participants participants .select { |p| p[:admin] } .map { |p| p[:id] } end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/whatsapp/group.rb', line 79 def inspect "#<Whatsapp::Group id=#{id.inspect} subject=#{subject.inspect} size=#{size}>" end |
#participant_ids ⇒ Array<String>
List of all participant JIDs.
60 61 62 63 64 |
# File 'lib/whatsapp/group.rb', line 60 def participant_ids return [] unless participants participants.map { |p| p[:id] } end |
#to_h ⇒ Hash
Returns serialized group info.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/whatsapp/group.rb', line 67 def to_h { id: id, subject: subject, description: description, owner: owner, creation: creation, size: size, participants: participants } end |