class IRuby::Input::Builder
Attributes
Public Class Methods
Source
# File lib/iruby/input/builder.rb, line 6 def initialize &block @processors = {} @fields, @buttons = [], [] instance_eval &block end
Public Instance Methods
Source
# File lib/iruby/input/builder.rb, line 12 def add_field field @fields << field end
Source
# File lib/iruby/input/builder.rb, line 21 def html &block add_field Class.new(Widget) { define_method(:widget_html) { instance_eval &block } }.new end
Source
# File lib/iruby/input/builder.rb, line 31 def password key='password', **params input key, **params.merge(type: 'password') end
Source
# File lib/iruby/input/builder.rb, line 35 def process_result result unless result.nil? result.each_with_object({}) do |(k,v),h| if @processors.has_key? k @processors[k].call h, k, v else h[k.to_sym] = v end end end end
Source
# File lib/iruby/input/builder.rb, line 27 def text string html { label string } end
Private Instance Methods
Source
# File lib/iruby/input/builder.rb, line 49 def process key, &block @processors[key.to_s] = block end
Source
# File lib/iruby/input/builder.rb, line 53 def unique_key key @keys ||= [] if @keys.include? key (2..Float::INFINITY).each do |i| test = "#{key}#{i}" break key = test unless @keys.include? test end end @keys << key; key end