Class: Urbit::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/urbit/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, members:, policy:, tags:, hidden:) ⇒ Group

Returns a new instance of Group.



8
9
10
11
12
13
14
15
16
# File 'lib/urbit/group.rb', line 8

def initialize(path:, members:, policy:, tags:, hidden:)
  @graphs  = Set.new
  @hidden  = hidden
  @manager = nil
  @members = Set.new(members)
  @path    = path
  @policy  = policy
  @tags    = self.parse_tags(tags)
end

Instance Attribute Details

#graphsObject

Returns the value of attribute graphs.



5
6
7
# File 'lib/urbit/group.rb', line 5

def graphs
  @graphs
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



6
7
8
# File 'lib/urbit/group.rb', line 6

def hidden
  @hidden
end

#managerObject

Returns the value of attribute manager.



5
6
7
# File 'lib/urbit/group.rb', line 5

def manager
  @manager
end

#membersObject

Returns the value of attribute members.



5
6
7
# File 'lib/urbit/group.rb', line 5

def members
  @members
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/urbit/group.rb', line 6

def path
  @path
end

#policyObject (readonly)

Returns the value of attribute policy.



6
7
8
# File 'lib/urbit/group.rb', line 6

def policy
  @policy
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/urbit/group.rb', line 5

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/urbit/group.rb', line 5

def title
  @title
end

Instance Method Details

#<=>(another_group) ⇒ Object



22
23
24
# File 'lib/urbit/group.rb', line 22

def <=>(another_group)
  self.path <=> another_group.path
end

#==(another_group) ⇒ Object



18
19
20
# File 'lib/urbit/group.rb', line 18

def ==(another_group)
  another_group.path == self.path
end

#creatorObject



26
27
28
29
# File 'lib/urbit/group.rb', line 26

def creator
  self.fetch_link if @creator.nil?
  @creator
end

#deleteObject

This is the action labeled as “Archive” in the Landscape UI. As of now, you can only do this to groups on your own ship.



40
41
42
43
44
45
46
47
# File 'lib/urbit/group.rb', line 40

def delete
  if (self.host == self.manager.ship.name)
    spdr = self.manager.spider('group-delete', %Q({"remove": {"ship": "#{self.host}", "name": "#{self.key}"}}))
    self.manager.remove(self) if 200 == spdr[:status]
    return spdr
  end
  {status: 400, code: 'bad_request', body: 'Can only delete Groups on your own ship.'}
end

#descriptionObject



31
32
33
34
# File 'lib/urbit/group.rb', line 31

def description
  self.fetch_link if @description.nil?
  @description
end

#eql?(another_group) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/urbit/group.rb', line 49

def eql?(another_group)
  another_group.path == self.path
end

#hostObject



60
61
62
# File 'lib/urbit/group.rb', line 60

def host
  self.path_tokens[0]
end

#invite(ship_names:, message:) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/urbit/group.rb', line 64

def invite(ship_names:, message:)
  data = %Q({
    "invite": {
      "resource": {
        "ship": "#{self.host}",
        "name": "#{self.key}"
      },
      "ships": [
        "#{ship_names.join(',')}"
      ],
      "description": "#{message}"
    }
  })
  self.manager.spider('group-invite', data)
end

#keyObject



80
81
82
# File 'lib/urbit/group.rb', line 80

def key
  self.path_tokens[1]
end

#leaveObject



84
85
86
87
88
# File 'lib/urbit/group.rb', line 84

def leave
  spdr = self.manager.spider('group-leave', %Q({"leave": {"ship": "#{self.host}", "name": "#{self.key}"}}))
  self.manager.remove(self) if 200 == spdr[:status]
  spdr
end

#path_tokensObject



90
91
92
# File 'lib/urbit/group.rb', line 90

def path_tokens
  self.path.split('/')
end

#pending_invitesObject



94
95
96
97
98
99
100
101
# File 'lib/urbit/group.rb', line 94

def pending_invites
  if (i = @policy["invite"])
    if (p = i["pending"])
      return p.count
    end
  end
  '?'
end

#pictureObject



103
104
105
106
# File 'lib/urbit/group.rb', line 103

def picture
  self.fetch_link if @picture.nil?
  @picture
end

#to_hObject



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/urbit/group.rb', line 113

def to_h
{
    title:           self.title,
    description:     self.description,
    host:            self.host,
    key:             self.key,
    member_count:    self.members.count,
    pending_invites: self.pending_invites,
    hidden:          self.hidden
  }
end

#to_listObject



125
126
127
# File 'lib/urbit/group.rb', line 125

def to_list
  self.title || "Untitled - #{self.path}"
end

#to_sObject



129
130
131
# File 'lib/urbit/group.rb', line 129

def to_s
  "a Group(#{self.to_h})"
end