aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/people_list.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-22 16:55:54 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-22 16:55:54 +0100
commit25b32914b72a5f709eca773f3511cc89c2e710c2 (patch)
tree4dab9e78e4c6b49220a837b38d463328c05e2983 /lib/mauve/people_list.rb
parent3185e5d746abda1b7f42ecdbd74ec14359fda3bc (diff)
parentfd23821950f0562a8995735105cd31fdc6d55933 (diff)
merge
Diffstat (limited to 'lib/mauve/people_list.rb')
-rw-r--r--lib/mauve/people_list.rb38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/mauve/people_list.rb b/lib/mauve/people_list.rb
index 32e0708..b15db3f 100644
--- a/lib/mauve/people_list.rb
+++ b/lib/mauve/people_list.rb
@@ -7,23 +7,43 @@ module Mauve
# Stores a list of name.
#
# @author Yann Golanski
- class PeopleList < Struct.new(:label, :list)
+ class PeopleList
- # Default contrustor.
- def initialize (*args)
- super(*args)
- end
+ attr_reader :label, :list
- def label
- self[:label]
+ # Default contrustor.
+ def initialize(label)
+ raise ArgumentError, "people_list label must be a string" unless label.is_a?(String)
+ @label = label
+ @list = []
end
alias username label
- def list
- self[:list] || []
+ def +(arr)
+ case arr
+ when Array
+ arr = arr.flatten
+ when String
+ arr = [arr]
+ else
+ logger.warn "Not sure what to do with #{arr.inspect} -- converting to string, and continuing"
+ arr = [arr.to_s]
+ end
+
+ arr.each do |person|
+ if @list.include?(person)
+ logger.warn "#{person} is already on the #{self.label} list"
+ else
+ @list << person
+ end
+ end
+
+ self
end
+ alias add_to_list +
+
#
# Set up the logger
def logger