A tiny assistant for CUI operations.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Split tutorial files May 13, 2013
lib/io Bump version to 0.1.2.2 with tweaks Jun 17, 2015
spec Update dependencies with more strictly specs Jun 17, 2015
.gitignore Add ignores for git May 12, 2013
.travis.yml
.yardopts Improve environments May 12, 2013
Gemfile
MIT-LICENSE Rename license file May 12, 2013
README.md Improve README Jun 17, 2015
Rakefile Improve environments May 12, 2013
io-nosey.gemspec Improve gemspec Jun 17, 2015

README.md

io-nosey

Build Status Gem Version Dependency Status

Description

A tiny assistant for CUI operations.

Features

  • #ask
  • #agree?
  • #choose
  • PureRuby :)

#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

  • default # when null input
  • echo # set "echo is (true or false)"
  • error # change error message when invalid input
  • multi_line # prefer multi_line mode for inputs(exit via ctrl+d)

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.