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.



659
660
661
662
663
# File 'lib/wee/html_brushes.rb', line 659

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

Instance Method Details

#add_callback(callback) ⇒ Object



665
666
667
668
669
# File 'lib/wee/html_brushes.rb', line 665

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

#call(value) ⇒ Object



671
672
673
674
675
676
677
678
# File 'lib/wee/html_brushes.rb', line 671

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