Class: Group::Members

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/Olib/character/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMembers

Returns a new instance of Members.


33
34
35
36
# File 'lib/Olib/character/group.rb', line 33

def initialize
  @birth   = Time.now
  @members = []
end

Instance Attribute Details

#birthObject

Returns the value of attribute birth


32
33
34
# File 'lib/Olib/character/group.rb', line 32

def birth
  @birth
end

#leaderObject

Returns the value of attribute leader


32
33
34
# File 'lib/Olib/character/group.rb', line 32

def leader
  @leader
end

#membersObject

Returns the value of attribute members


32
33
34
# File 'lib/Olib/character/group.rb', line 32

def members
  @members
end

Instance Method Details

#add(pc, leader = false) ⇒ Object


52
53
54
55
56
57
58
59
# File 'lib/Olib/character/group.rb', line 52

def add(pc, leader = false)      
  member = Member.new pc, leader
  if leader
    @leader = member
  end
  @members << member
  self
end

#clear!Object


38
39
40
41
42
# File 'lib/Olib/character/group.rb', line 38

def clear!
  @members = []
  @birth   = Time.now
  @leader  = nil
end

#each(&block) ⇒ Object


61
62
63
64
# File 'lib/Olib/character/group.rb', line 61

def each(&block)
  @members.each { |char| yield char }
  self
end

#empty?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/Olib/character/group.rb', line 48

def empty?
  @members.empty?
end

#include?(pc) ⇒ Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/Olib/character/group.rb', line 66

def include?(pc)
  select { |char| char.name == pc }
end

#nonmembersObject


70
71
72
73
74
# File 'lib/Olib/character/group.rb', line 70

def nonmembers
  (GameObj.pcs || []).reject do |pc|
    @members.include?(pc)
  end
end

#sizeObject


44
45
46
# File 'lib/Olib/character/group.rb', line 44

def size
  @members.size
end

#to_sObject


76
77
78
# File 'lib/Olib/character/group.rb', line 76

def to_s
  "<Members: [#{@members.join(" ")}]>"
end