Giter Site home page Giter Site logo

inputs's Introduction

Build Status Open Thanks

Inputs

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

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.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

inputs's People

Contributors

equivalent avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.