diff options
Diffstat (limited to 'lib/mauve/people_list.rb')
-rw-r--r-- | lib/mauve/people_list.rb | 38 |
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 |