Class: Wee::Brush::RadioGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/wee/html_brushes.rb

Overview


Form - Radio


Instance Method Summary collapse

Constructor Details

#initialize(canvas) ⇒ RadioGroup

Returns a new instance of RadioGroup.



612
613
614
615
616
# File 'lib/wee/html_brushes.rb', line 612

def initialize(canvas)
  @name = canvas.register_callback(:input, self)
  @callbacks = {}
  @ids = Wee::IdGenerator::Sequential.new 
end

Instance Method Details

#add_callback(callback) ⇒ Object



618
619
620
621
622
# File 'lib/wee/html_brushes.rb', line 618

def add_callback(callback)
  value = @ids.next.to_s
  @callbacks[value] = callback
  return [@name, value]
end

#call(value) ⇒ Object



624
625
626
627
628
629
630
631
# File 'lib/wee/html_brushes.rb', line 624

def call(value)
  if @callbacks.has_key?(value)
    cb = @callbacks[value]
    cb.call(value) if cb
  else
    raise "invalid radio button/group value"
  end
end