inputs 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +84 -3
- data/inputs.gemspec +1 -0
- data/lib/inputs.rb +12 -0
- data/lib/inputs/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81803c73d9c385182e658da5427ddb0e751bf7f7
|
4
|
+
data.tar.gz: 34f780896f20a7e2ffd9217268f899b52102e076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93911d3fbfd8558a9fd975021336153ca2068c6a8cb58656166179beae087a9bbeb69034c19a24f39a4d857ad1cedcc0e54c74726938995c70074bad2c568179
|
7
|
+
data.tar.gz: 41c90ac69ef580ff00647a1f01bae6787195ab7743e1cdf3e9d2d3eca9548fb811529026e822900852958285cfdde304212f3ef9d881f0eaab20d0eedfcb9247
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
[](https://travis-ci.org/equivalent/inputs)
|
2
|
+

|
3
|
+
[](https://thawing-falls-79026.herokuapp.com/r/fpjrqlob)
|
4
|
+
|
1
5
|
# Inputs
|
2
6
|
|
3
7
|
Really stupid primitive Gem that will handle some common console operations.
|
4
8
|
|
9
|
+
The gem aims to be really simple. If you looking for something more complex I recommend to use
|
10
|
+
[TTY](http://piotrmurach.github.io/tty/),[tty-prompt](https://github.com/piotrmurach/tty-prompt)
|
11
|
+
|
12
|
+
[Reddit discussion](https://www.reddit.com/r/ruby/comments/4i5dep/gem_inputs_another_pointless_gem_for_handling/)
|
13
|
+
|
5
14
|
```
|
6
15
|
require 'inputs'
|
7
16
|
|
@@ -13,6 +22,10 @@ Inputs.name('What is your name')
|
|
13
22
|
# What is your name
|
14
23
|
# => String
|
15
24
|
|
25
|
+
Inputs.name!('Do you want to skip this question?')
|
26
|
+
# What is your name
|
27
|
+
# => String or Nil if no input
|
28
|
+
|
16
29
|
Inputs.names('Names of your parents')
|
17
30
|
# Names of your parents
|
18
31
|
# => Array
|
@@ -31,17 +44,85 @@ Inputs.pick(['cat', 'dog'])
|
|
31
44
|
|
32
45
|
## Installation
|
33
46
|
|
34
|
-
|
47
|
+
Option 1:
|
48
|
+
|
49
|
+
`gem install inputs`
|
50
|
+
|
51
|
+
Option 2 (If you use `bundler`) :
|
35
52
|
|
36
53
|
```ruby
|
37
|
-
|
54
|
+
# Gemfile
|
55
|
+
gem 'inputs'
|
38
56
|
```
|
39
57
|
|
40
58
|
And then execute:
|
41
59
|
|
42
|
-
|
60
|
+
```bash
|
61
|
+
$ bundle
|
62
|
+
```
|
63
|
+
|
64
|
+
## Example
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# foo.rb
|
68
|
+
require 'inputs'
|
69
|
+
|
70
|
+
class Foo
|
71
|
+
def call
|
72
|
+
name = Inputs.name("what is your name")
|
73
|
+
|
74
|
+
if Inputs.yn("Ok #{name}, do you want to learn music instrument?")
|
75
|
+
instrument = Inputs.pick(instrument_options)
|
76
|
+
|
77
|
+
case instrument
|
78
|
+
when drums
|
79
|
+
puts 'Metal dude ! \,,/'
|
80
|
+
when guitar
|
81
|
+
puts "Rock on dude !"
|
82
|
+
when harp
|
83
|
+
puts "W.T.F dude ?"
|
84
|
+
end
|
85
|
+
else
|
86
|
+
puts "Then go home #{name} !"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def instrument_options
|
92
|
+
[
|
93
|
+
drums,
|
94
|
+
guitar,
|
95
|
+
harp
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
def drums
|
100
|
+
'Drums'
|
101
|
+
end
|
102
|
+
|
103
|
+
def guitar
|
104
|
+
'Guitar'
|
105
|
+
end
|
106
|
+
|
107
|
+
def harp
|
108
|
+
'Harp'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
Foo.new.call
|
113
|
+
```
|
114
|
+
|
115
|
+

|
43
116
|
|
44
117
|
## License
|
45
118
|
|
46
119
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
47
120
|
|
121
|
+
## Contribution
|
122
|
+
|
123
|
+
I welcome any suggestions & Pull Requests. Currently there is not lot of
|
124
|
+
tests as I thought I will never release this lib so if you decide to do
|
125
|
+
a PR please write a test.
|
126
|
+
|
127
|
+
Thank you
|
128
|
+
|
data/inputs.gemspec
CHANGED
data/lib/inputs.rb
CHANGED
@@ -17,6 +17,7 @@ module Inputs
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
# Outputs a question and returns an input string. If no string is typed it returns empty string ("")
|
20
21
|
def self.name(question)
|
21
22
|
output question
|
22
23
|
name = _input_evaluator.call
|
@@ -25,6 +26,17 @@ module Inputs
|
|
25
26
|
name
|
26
27
|
end
|
27
28
|
|
29
|
+
# Outputs a question and returns an input string. If no string is typed it returns nil
|
30
|
+
def self.name!(question)
|
31
|
+
output question
|
32
|
+
name = _input_evaluator.call
|
33
|
+
name = name.chomp
|
34
|
+
if name != ''
|
35
|
+
output name.green
|
36
|
+
name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
28
40
|
def self.names(question)
|
29
41
|
output question + " (Comma separated)"
|
30
42
|
names = _input_evaluator.call
|
data/lib/inputs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inputs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Valent
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '11.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '11.1'
|
69
83
|
description: 'Stupid pointless gem for lazy Ruby developer to implement console interfaces
|
70
84
|
for input fields like y/n questions, names, ... '
|
71
85
|
email:
|
@@ -107,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
121
|
version: '0'
|
108
122
|
requirements: []
|
109
123
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.5.1
|
111
125
|
signing_key:
|
112
126
|
specification_version: 4
|
113
127
|
summary: Pointless Gem for creating console input interfaces
|