Sha256: 8cd161dc54f6cdc8e9981a731bb33087a7ce4c85db78f36b67f7c2ea0c03795c

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

module Netprint
  class Options
    attr_reader :options

    def initialize(options = {})
      @options = {
        :paper_size  => PAPERSIZE::A4,
        :color       => COLOR::BW,
        :code_type   => CODE_TYPE::ALNUM,
        :secret_code => nil,
        :email       => nil
      }.merge(options)
    end

    def apply(form)
      check_radiobutton(form, 'yus-size',       options[:paper_size])
      check_radiobutton(form, 'iro-cl',         options[:color])
      check_radiobutton(form, 'yyk-type-cl',    options[:code_type])
      check_radiobutton(form, 'pin-num-set-fl', options[:secret_code] =~ /^\d{4}$/ ? '1' : '0')
      check_radiobutton(form, 'notice-onoff',   options[:email] ? '1' : '0')

      form['pin-no']         = options[:secret_code] if options[:secret_code] =~ /^\d{4}$/
      form['mail-adr-to-tx'] = options[:email]       if options[:email]
    end

    private

    def check_radiobutton(form, name, value)
      form.radiobutton_with(:name => name, :value => value).check
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
netprint-0.3.4 lib/netprint/options.rb
netprint-0.3.3 lib/netprint/options.rb
netprint-0.3.1 lib/netprint/options.rb
netprint-0.3.0 lib/netprint/options.rb