Sha256: 3731d6bab1fdd7282703e200cb9dac1d9cdbeba7344b38573c7587e38110981f

Contents?: true

Size: 721 Bytes

Versions: 1

Compression:

Stored size: 721 Bytes

Contents

require 'delegate'

module Interactive
  module_function

  def Option(option)
    if option.to_s.match(/^\d+$/)
      @option = WholeNumberOption.new(option)
    else
      @option = WordOption.new(option)
    end

    @option
  end

  class WholeNumberOption < SimpleDelegator
    def initialize(option)
      @option = option
      super(@option)
    end

    def shortcut_value
      @option
    end

    def query_method_name
      "whole_number_#{shortcut_value}?"
    end
  end

  class WordOption < SimpleDelegator
    def initialize(option)
      @option = option
      super(@option)
    end

    def shortcut_value
      @option.to_s[0]
    end

    def query_method_name
      "#{@option}?"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interactive-0.1.0 lib/interactive/option.rb