io-nosey

A tiny assistant for CUI operations

Download as .zip Download as .tar.gz View on GitHub

io-nosey

Build Status Gem Version

Description

A tiny assistant for CUI operations.

Features

#ask's option parameter

input -> parse -> return

  1. input # validation for input string
  2. parse # procedure for input string
  3. return # validation for return value

Other

Usage

Tutorial

Try below senario on REPL(ex. irb, pry) or excute "example/**_tutorial.rb"

require 'io/nosey'
include IO::Nosey

# input validation
ask 'What\'s your name?("firstname lastname"): ', input: /\A\w+ \w+\z/

# mix the validations and procedures
ask 'How old are you?: ', input:  /\A(\d+)\z/,
                          parse:  ->s{Integer s},
                          return: 10..100

# default value
ask "What's your favorite?: ", default: 'ruby'

# yes or no
agree? 'Do you like this API?: '

# for password
ask "What's your password?: ", echo: false

# choose one from collections
choose 'Which Five do you like?: ',  5      => '5 is a Integer',
                                   'five' => '"five" is a String',
                                   :FIVE  => ':FIVE is a Symbol'

# multi line mode
ask 'Write your poem and exit ctrl+d :) ', multi_line: true

Requirements

Install

gem install io-nosey

Link

License

The MIT X11 License
Copyright (c) 2011 Kenichi Kamiya
See MIT-LICENSE for further details.