Project

inputs

0.0
No commit activity in last 3 years
No release in over 3 years
Stupid pointless gem for lazy Ruby developer to implement console interfaces for input fields like y/n questions, names, ...
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 0.10
~> 11.1
~> 3

Runtime

~> 0.7
 Project Readme

Build Status Gittens Open Thanks

Inputs

Really stupid primitive Gem that will handle some common console operations.

Don't want to install gem ? There is a copy-paste version for your script Inputs copy-paste version

The gem aims to be really simple. If you looking for something more complex I recommend to use TTY,tty-prompt Reddit discussion

require 'inputs'

Inputs.yn('Are you stupid?')
# Are you stupid? [y/n]
# => true / false

Inputs.name('What is your name')
# What is your name
# => String

Inputs.name!('Do you want to skip this question?')
# What is your name
# => String or Nil if no input

Inputs.password('What is the password: ')
# What is the password: 
# => String

Inputs.names('Names of your parents')
# Names of your parents
# => Array

Inputs.pick(['cat', 'dog'])
# Please choose
#   Press 1 for "cat"
#   Press 2 for "dog"

## after pressing 1
# => 'cat'

## after pressing 2
# => 'dog'

Installation

Option 1:

gem install inputs

Option 2 (If you use bundler) :

# Gemfile
gem 'inputs'

And then execute:

$ bundle

Example

# foo.rb
require 'inputs'

class Foo
  def call
    name = Inputs.name("what is your name")

    if Inputs.yn("Ok #{name}, do you want to learn music instrument?")
      instrument = Inputs.pick(instrument_options)

      case instrument
      when drums
        puts 'Metal dude ! \,,/'
      when guitar
        puts "Rock on dude !"
      when harp
        puts "W.T.F dude ?"
      end
    else
      puts "Then go home #{name} !"
    end
  end

  private
    def instrument_options
      [
        drums,
        guitar,
        harp
      ]
    end

    def drums
      'Drums'
    end

    def guitar
      'Guitar'
    end

    def harp
      'Harp'
    end
end

Foo.new.call

Inputs gem example

License

The gem is available as open source under the terms of the MIT License.

Contribution

I welcome any suggestions & Pull Requests. Currently there is not lot of tests as I thought I will never release this lib so if you decide to do a PR please write a test.

Thank you