Class: Irc::Bot::Config::ArrayValue

Inherits:
Value show all
Defined in:
/home/apoc/projects/ruby/rbot/lib/rbot/config.rb

Instance Attribute Summary

Attributes inherited from Value

#auth_path, #desc, #key, #manager, #order, #requires_rescan, #requires_restart, #store_default, #type, #wizard

Instance Method Summary (collapse)

Methods inherited from Value

#default, #get, #set, #set_string, #unset

Constructor Details

- (ArrayValue) initialize(key, params)

Returns a new instance of ArrayValue



168
169
170
171
172
173
174
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 168

def initialize(key, params)
  super
  @validate_item = params[:validate_item]
  @validate ||= Proc.new do |v|
    !v.find { |i| !validate_item(i) }
  end
end

Instance Method Details

- (Object) add(val)



186
187
188
189
190
191
192
193
194
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 186

def add(val)
  newval = self.get.dup
  unless newval.include? val
    newval << val
    validate_item(val) or raise ArgumentError, "invalid item: #{val}"
    validate(newval) or raise ArgumentError, "invalid value: #{newval.inspect}"
    set(newval)
  end
end

- (Object) parse(string)



180
181
182
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 180

def parse(string)
  string.split(/,\s+/)
end

- (Object) rm(val)

Raises:

  • (ArgumentError)


195
196
197
198
199
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 195

def rm(val)
  curval = self.get
  raise ArgumentError, "value #{val} not present" unless curval.include?(val)
  set(curval - [val])
end

- (Object) to_s



183
184
185
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 183

def to_s
  get.join(", ")
end

- (Object) validate_item(item)



176
177
178
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 176

def validate_item(item)
  validate(item, @validate_item)
end