highline_wizard 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in highline-wizard.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Guillermo Álvarez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # Highline::Wizard
2
+
3
+ Highline Wizard is a library to help you getting options. That options should be passed as a 2 dimension array.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'highline-wizard'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install highline-wizard
19
+
20
+ ## Usage
21
+
22
+ In your ruby script
23
+
24
+ ```ruby
25
+ require 'highline/wizard'
26
+
27
+ OPTIONS = [
28
+ %W( icecream chocolate extra-topping 4.5 )
29
+ %W( icecream chocolate no-topping 3.5 )
30
+ %W( cake chocolate no-topping 4.5 )
31
+ %W( cake vanilla no-topping 4.5 )
32
+ ]
33
+
34
+ selected = wizzard(OPTIONS) do
35
+ titles << %w(desert flavor extra price)
36
+ end
37
+
38
+ puts selected.inspect
39
+
40
+ ```
41
+
42
+ This will generate to the user the following conversation:
43
+
44
+ ```shell
45
+ 1. icecream
46
+ 2. cake
47
+ Choose desert? 2
48
+
49
+ 1. chocolate
50
+ 2. vanilla
51
+ Choose flavor? 1
52
+
53
+ { "desert" => "cake", "flavor" => "chocolate", "extra" => "no-toppinng", "price" => "4.5" }
54
+ ```
55
+
56
+ Other option:
57
+
58
+ ```shell
59
+ 1. icecream
60
+ 2. cake
61
+ Choose desert? 1
62
+
63
+ 1. extra-topping
64
+ 2. no-topping
65
+ Choose extra? 2
66
+
67
+ { "desert" => "icecream", "flavor" => "chocolate", "extra" => "no-topping", "price" => "4.5" }
68
+
69
+ ```
70
+
71
+ As you can see, options that are not possible are not asked.
72
+
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ sh "ruby -I lib test/hl_wizard_test.rb"
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'highline/wizard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "highline_wizard"
8
+ spec.version = Highline::Wizard::VERSION
9
+ spec.authors = ["Guillermo Álvarez"]
10
+ spec.email = ["guillermo@cientifico.net"]
11
+ spec.description = %q{Interactive array based wizzard bassed in highline}
12
+ spec.summary = %q{Let the people choose and focus in your program}
13
+ spec.homepage = "http://github.com/guillermo/highline_wizzard"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "highline"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "minitest"
26
+ end
@@ -0,0 +1,67 @@
1
+ require "highline/wizard/version"
2
+ require 'highline'
3
+
4
+ module Highline
5
+ module Wizard
6
+ class Wizzard
7
+ attr_reader :selected
8
+ def initialize(data = nil)
9
+ @options = Struct.new(:titles, :defaults, :data).new
10
+ @options.defaults = []
11
+ @options.titles = []
12
+ @options.data ||= data
13
+ @options.data.freeze
14
+ @hl = HighLine.new
15
+ yield @options if block_given?
16
+
17
+ result = []
18
+ current_data = data.dup
19
+ columns_count.times do |column_index|
20
+ values = current_data.transpose[column_index].uniq
21
+ choosen = nil
22
+ if values.size > 1
23
+ elected = choose(values, @options.titles[column_index], @options.defaults[column_index])
24
+ else
25
+ elected = values.first
26
+ end
27
+
28
+ result << elected
29
+
30
+ current_data = current_data.select{|row|
31
+ row[column_index] == elected
32
+ }
33
+
34
+ end
35
+ @selected = result
36
+ end
37
+
38
+ def choose(values, title, default = nil)
39
+ @hl.choose(*(values.sort)) do |menu|
40
+ default = nil unless values.include?(default)
41
+ prompt = "Please choose"
42
+ prompt << " #{title}" if title
43
+ prompt << " ( Default: #{default} )" if default
44
+ menu.prompt = prompt
45
+ menu.default = default if default
46
+ end
47
+ end
48
+
49
+ protected
50
+ def data
51
+ @options.data
52
+ end
53
+
54
+ def columns_count
55
+ columns.size
56
+ end
57
+
58
+ def columns
59
+ data.transpose
60
+ end
61
+ end
62
+
63
+ def wizzard(data = nil, &block)
64
+ Wizzard.new(data,&block).selected
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ module Highline
2
+ module Wizard
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'highline/wizard'
2
+
3
+ include Highline::Wizard
4
+
5
+ OPTIONS = [
6
+ %W( icecream chocolate extra-topping 4.5 ),
7
+ %W( icecream chocolate no-topping 3.5 ),
8
+ %W( cake chocolate no-topping 4.5 ),
9
+ %W( cake vanilla no-topping 4.5 ),
10
+ %W( coffe coffe no-topping 4.5 ),
11
+ %W( coffe coffe chocolate-topping 4.5 )
12
+ ]
13
+
14
+ selected = wizzard(OPTIONS) do |q|
15
+ q.titles = %w(desert flavor extra price)
16
+ q.defaults = [ "icecream", "vanilla", "extra-topping", "4.5" ]
17
+ end
18
+
19
+ puts selected.inspect
20
+
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: highline_wizard
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - "Guillermo \xC3\x81lvarez"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-04-19 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ name: highline
23
+ type: :runtime
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ name: bundler
37
+ type: :development
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 9
44
+ segments:
45
+ - 1
46
+ - 3
47
+ version: "1.3"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ name: rake
52
+ type: :development
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ name: minitest
66
+ type: :development
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirement: *id004
77
+ description: Interactive array based wizzard bassed in highline
78
+ email:
79
+ - guillermo@cientifico.net
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files: []
85
+
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - highline_wizard.gemspec
93
+ - lib/highline/wizard.rb
94
+ - lib/highline/wizard/version.rb
95
+ - test/hl_wizard_test.rb
96
+ homepage: http://github.com/guillermo/highline_wizzard
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.24
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Let the people choose and focus in your program
129
+ test_files:
130
+ - test/hl_wizard_test.rb