girls_bar 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.rspec +2 -0
  4. data/README.md +1 -1
  5. data/Rakefile +4 -0
  6. data/bin/girls_bar +5 -5
  7. data/girls_bar.gemspec +8 -3
  8. data/lib/girls_bar.rb +46 -42
  9. data/lib/girls_bar/command/confirm.rb +55 -0
  10. data/lib/girls_bar/command/input.rb +43 -0
  11. data/lib/girls_bar/command/redirect.rb +14 -0
  12. data/lib/girls_bar/command/restart.rb +10 -0
  13. data/lib/girls_bar/command/script.rb +17 -0
  14. data/lib/girls_bar/constants.rb +2 -2
  15. data/lib/girls_bar/data.rb +20 -0
  16. data/lib/girls_bar/entry.rb +77 -0
  17. data/lib/girls_bar/filter.rb +10 -13
  18. data/lib/girls_bar/helper.rb +1 -2
  19. data/lib/girls_bar/router.rb +87 -0
  20. data/lib/girls_bar/settings.rb +28 -0
  21. data/lib/girls_bar/version.rb +1 -1
  22. data/spec/girls_bar/command/confirm_spec.rb +5 -0
  23. data/spec/girls_bar/command/input_spec.rb +5 -0
  24. data/spec/girls_bar/command/redirect_spec.rb +5 -0
  25. data/spec/girls_bar/command/restart_spec.rb +5 -0
  26. data/spec/girls_bar/command/script_spec.rb +5 -0
  27. data/spec/girls_bar/constants_spec.rb +5 -0
  28. data/spec/girls_bar/data_spec.rb +5 -0
  29. data/spec/girls_bar/entry_spec.rb +5 -0
  30. data/spec/girls_bar/filter_spec.rb +5 -0
  31. data/spec/girls_bar/helper_spec.rb +18 -0
  32. data/spec/girls_bar/router_spec.rb +5 -0
  33. data/spec/girls_bar/settings_spec.rb +5 -0
  34. data/spec/girls_bar/version_spec.rb +8 -0
  35. data/spec/girls_bar_spec.rb +5 -0
  36. data/spec/spec_helper.rb +5 -0
  37. metadata +92 -9
  38. data/lib/girls_bar/app.rb +0 -28
  39. data/lib/girls_bar/command.rb +0 -130
  40. data/lib/girls_bar/config.rb +0 -36
  41. data/lib/girls_bar/controller.rb +0 -92
  42. data/lib/girls_bar/model.rb +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 942c884b813e73a9ce88301768e06c12156401e8
4
- data.tar.gz: 7bca2fa0474f6517a3deda228abad4fe6a917880
3
+ metadata.gz: 4c5079613266346049d8ac57135d61f1c63b9176
4
+ data.tar.gz: 55252e117efb2753d5a55c8ec16e83109d5bc1bc
5
5
  SHA512:
6
- metadata.gz: d3e623d1a43eb14d54bc37a1de42ed5a9cc475645d64c42cf1e9362a82ed521888c8709c63a383b1c50840b07daacd082958a27a653a49025b74b671c01dbd38
7
- data.tar.gz: ef9962e64c4b4eb5613d89643aa06ff5898025c74f10a30bdd28e01cb662c96f1cfc2df039333a9a487eb4843c0c102e845d03a0055e113237992442e19c0ef8
6
+ metadata.gz: ac70b70771a4b38bf371ce58d09058c365bdd973256a5c7ebc7a2e4cb881cb15a4b88783f5adbe21698b2454dd1c6260211a6f50d4893e75805d957cd7e7e335
7
+ data.tar.gz: 008e2f8e41ae5f6f56d2f19afbd13924988a7bb36183052e591b169a020ab57be43102efe3971a09930795e24ebcfe506c45d2fbd571e4db6b1502255bc15670
data/.gitignore CHANGED
@@ -12,7 +12,6 @@
12
12
  *.o
13
13
  *.a
14
14
  *.gem
15
- *.yml
16
15
  *.json
17
16
  mkmf.log
18
17
 
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GirlsBar
1
+ # GirlsBar[![Build Status](https://travis-ci.org/YoshiyukiHirano/girls_bar.png)](https://travis-ci.org/YoshiyukiHirano/girls_bar)[![Coverage Status](https://coveralls.io/repos/YoshiyukiHirano/girls_bar/badge.png)](https://coveralls.io/r/YoshiyukiHirano/girls_bar)
2
2
 
3
3
  Create interactive CLI program from YAML or JSON.
4
4
 
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/girls_bar CHANGED
@@ -18,16 +18,16 @@ opts = OptionParser.new do |opts|
18
18
  if %(yml yaml json).include?(format)
19
19
  @format = format
20
20
  else
21
- GirlsBar::Helper.set_color(:red) do
21
+ GirlsBar::Helper.set_color(:red) {
22
22
  puts "Invalid Format: Available Format YAML or JSON"
23
- end
23
+ }
24
24
  end
25
25
  end
26
26
 
27
27
  opts.on_tail("-v", "--version", "Show version") do
28
- GirlsBar::Helper.set_color(:yellow) do
28
+ GirlsBar::Helper.set_color(:yellow) {
29
29
  puts "GirlsBar version #{GirlsBar::VERSION} on Ruby #{RUBY_VERSION}"
30
- end
30
+ }
31
31
  exit
32
32
  end
33
33
  end
@@ -45,7 +45,7 @@ when "generate", "g"
45
45
  GirlsBar.generate(@format)
46
46
  when "open", "run", "serve", "start", "init", "boot", "s"
47
47
  path = ARGV.shift.strip
48
- GirlsBar.boot(path)
48
+ GirlsBar.run(path)
49
49
  else
50
50
  puts opts
51
51
  exit 1
data/girls_bar.gemspec CHANGED
@@ -18,7 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "pry", '~> 0.10', '>= 0.10.1'
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency 'bundler', ['~> 1.7']
24
+ spec.add_development_dependency 'rake', ['~> 10.0']
25
+ spec.add_development_dependency 'rspec', ['~> 0']
26
+ spec.add_development_dependency 'pry', ['~> 0.10', '>= 0.10.1']
27
+ spec.add_development_dependency 'coveralls', ['~> 0.7', '>= 0.7.3']
28
+ spec.add_development_dependency 'rdoc', ['~> 0']
24
29
  end
data/lib/girls_bar.rb CHANGED
@@ -1,55 +1,59 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "yaml"
3
3
  require "json"
4
-
5
- require "girls_bar/version"
4
+ require "girls_bar/command/confirm"
5
+ require "girls_bar/command/input"
6
+ require "girls_bar/command/redirect"
7
+ require "girls_bar/command/restart"
8
+ require "girls_bar/command/script"
6
9
  require "girls_bar/constants"
7
- require "girls_bar/config"
8
- require "girls_bar/model"
9
- require "girls_bar/command"
10
- require "girls_bar/controller"
11
- require "girls_bar/helper"
10
+ require "girls_bar/data"
11
+ require "girls_bar/entry"
12
12
  require "girls_bar/filter"
13
- require "girls_bar/app"
13
+ require "girls_bar/helper"
14
+ require "girls_bar/router"
15
+ require "girls_bar/settings"
16
+ require "girls_bar/version"
14
17
 
15
18
  module GirlsBar
16
- class << self
17
- def boot(path)
18
- begin
19
- raise "File Does Not Exist" unless FileTest.exist?(path)
20
- case File.extname(path)
21
- when '.yml'
22
- data = YAML.load_file path
23
- when '.json'
24
- data = JSON.load open(path)
25
- else
26
- raise 'Invalid File Extension'
27
- end
28
- GirlsBar::App.boot(data)
29
- rescue => e
30
- GirlsBar::Helper.set_color(:white, :on_red) do
31
- puts e.message
32
- end
33
- end
34
- end
19
+ def self.run(path)
20
+ resource = load_resource(path)
21
+ GirlsBar::Settings.setup resource["config"]
22
+ GirlsBar::Entry.setup resource["entry"]
23
+ GirlsBar::Data.setup
24
+ GirlsBar::Router.start
25
+ end
35
26
 
36
- def generate(format=nil)
37
- data = YAML.load GirlsBar::TEMPLATE
38
- if format == "json"
39
- filename = "tequila.json"
40
- open(filename, "w") {|io|
41
- io.write JSON.pretty_generate data
42
- }
27
+ def self.generate(format)
28
+ dump_resource(format)
29
+ end
30
+
31
+ private
32
+ def self.load_resource(path)
33
+ begin
34
+ raise "File Does Not Exist" unless FileTest.exist?(path)
35
+ case File.extname(path)
36
+ when ".yml"
37
+ resource = YAML.load_file path
38
+ when ".json"
39
+ resource = JSON.load open(path)
43
40
  else
44
- filename = "tequila.yml"
45
- open(filename, "w") {|io|
46
- io.write YAML.dump data
47
- }
48
- end
49
- GirlsBar::Helper.set_color(:blue) do
50
- puts "...Generated #{filename}"
41
+ raise "Invalid File Extension"
51
42
  end
43
+ rescue => e
44
+ GirlsBar::Helper.set_color(:white, :on_red) { puts e.message }
52
45
  end
53
46
  end
54
- end
55
47
 
48
+ def self.dump_resource(format=nil)
49
+ data = YAML.load GirlsBar::TEMPLATE
50
+ if format == "json"
51
+ filename = "tequila.json"
52
+ open(filename, "w") {|io| io.write JSON.pretty_generate data }
53
+ else
54
+ filename = "tequila.yml"
55
+ open(filename, "w") {|io| io.write YAML.dump data }
56
+ end
57
+ GirlsBar::Helper.set_color(:blue) { puts "...Generated #{filename}" }
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ module Command
4
+ class Confirm
5
+ def initialize(resource)
6
+ @subject = resource["subject"]
7
+ @selections = []
8
+ register_selections resource["select"]
9
+ end
10
+
11
+ def execute
12
+ while true
13
+ show_subject_and_selections
14
+ key = GirlsBar::Filter.to_id gets
15
+ case key
16
+ when "exit", "quit"
17
+ GirlsBar::Router.quit
18
+ when "help"
19
+ GirlsBar::Router.help
20
+ else
21
+ if selected = find_selection_by_key(key)
22
+ GirlsBar::Router.move(selected.link)
23
+ return true
24
+ end
25
+ end
26
+ GirlsBar::Router.retry
27
+ end
28
+ end
29
+
30
+ private
31
+ def register_selections(resource)
32
+ resource.each do |id, content|
33
+ @selections << GirlsBar::Selection.new(id, content["label"], content["link"])
34
+ end
35
+ end
36
+
37
+ def show_subject_and_selections
38
+ GirlsBar::Helper.set_color(:white) {
39
+ print "\n"
40
+ puts GirlsBar::Filter.to_subject @subject
41
+ puts GirlsBar::Settings.delimiter
42
+ @selections.each do |selection|
43
+ puts " #{selection.key}: " + GirlsBar::Filter.to_selection(selection.label)
44
+ end
45
+ puts GirlsBar::Settings.delimiter
46
+ }
47
+ print GirlsBar::Settings.prompt
48
+ end
49
+
50
+ def find_selection_by_key(key)
51
+ @selections.find {|x| x.key == key }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ module Command
4
+ class Input
5
+ def initialize(resource)
6
+ @subject = resource["subject"]
7
+ @id = GirlsBar::Filter.to_id resource["id"]
8
+ @link = GirlsBar::Filter.to_id resource["link"]
9
+ end
10
+
11
+ def execute
12
+ while true
13
+ show_subject
14
+ raw_data = gets
15
+ key = GirlsBar::Filter.to_id raw_data
16
+ case key
17
+ when "exit", "quit"
18
+ GirlsBar::Router.quit
19
+ when "help"
20
+ GirlsBar::Router.help
21
+ else
22
+ unless "#{key}".empty?
23
+ GirlsBar::Data.set @id, raw_data
24
+ GirlsBar::Router.move @link
25
+ return true
26
+ end
27
+ end
28
+ GirlsBar::Router.retry
29
+ end
30
+ end
31
+
32
+ private
33
+ def show_subject
34
+ GirlsBar::Helper.set_color(:white) {
35
+ print "\n"
36
+ puts GirlsBar::Filter.to_subject @subject
37
+ puts GirlsBar::Settings.delimiter
38
+ }
39
+ print GirlsBar::Settings.prompt
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ module Command
4
+ class Redirect
5
+ def initialize(resource)
6
+ @key = GirlsBar::Filter.to_id resource
7
+ end
8
+
9
+ def execute
10
+ GirlsBar::Router.move @key
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ module Command
4
+ class Restart
5
+ def execute
6
+ GirlsBar::Router.restart
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ module Command
4
+ class Script
5
+ def initialize(resource)
6
+ @script = resource
7
+ end
8
+
9
+ def execute
10
+ script = GirlsBar::Filter.to_script @script
11
+ GirlsBar::Helper.set_color(:green) { print "\n"; puts "=> run #{script}" }
12
+ res = %x( #{script} )
13
+ GirlsBar::Helper.set_color(:blue) { puts res }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -17,7 +17,7 @@ module GirlsBar
17
17
  clear: 0, bold: 1, black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenda: 35, cyan: 36, white: 37,
18
18
  on_black: 40, on_red: 41, on_green: 42, on_yellow: 43, on_blue: 44, on_magenda: 45, on_cyan: 46, on_white: 47
19
19
  }
20
- TEMPLATE = <<EOF
20
+ TEMPLATE = <<-EOF
21
21
  config:
22
22
  title: GirlsBar Title (Optional)
23
23
  description: |+
@@ -30,7 +30,7 @@ config:
30
30
  help_message: |+
31
31
  Show something... when you type 'help'.
32
32
  [Default] Type 'help' for help. Type 'exit' or 'quit' to quit.
33
- girls:
33
+ entry:
34
34
  input_your_name:
35
35
  input:
36
36
  subject: |
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ class Data
4
+ def self.setup
5
+ @data ||= {}
6
+ end
7
+
8
+ def self.get(key)
9
+ @data[key]
10
+ end
11
+
12
+ def self.set(key, value)
13
+ @data[key] = value.strip
14
+ end
15
+
16
+ def self.empty?
17
+ @data.empty?
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ class Entry
4
+ class << self
5
+ def setup(resource)
6
+ @data = []
7
+ resource.each_pair do |res|
8
+ @data << GirlsBar::Entry.new(res)
9
+ end
10
+ end
11
+
12
+ def all
13
+ @data
14
+ end
15
+
16
+ def first
17
+ @data.first
18
+ end
19
+ end
20
+
21
+ attr :id
22
+
23
+ def initialize(resource)
24
+ @id = GirlsBar::Filter.to_id resource[0]
25
+ @commands = []
26
+ register_commands resource[1]
27
+ end
28
+
29
+ def execute
30
+ @commands.map(&:execute)
31
+ end
32
+
33
+ private
34
+ def register_commands(resource)
35
+ add_command_script resource
36
+ add_command_input resource
37
+ add_command_confirm resource
38
+ add_command_redirect resource
39
+ add_command_restart resource
40
+ end
41
+
42
+ def add_command_script(resource)
43
+ return if resource["script"].nil?
44
+ @commands << GirlsBar::Command::Script.new(resource["script"])
45
+ end
46
+
47
+ def add_command_input(resource)
48
+ return if resource["input"].nil?
49
+ @commands << GirlsBar::Command::Input.new(resource["input"])
50
+ end
51
+
52
+ def add_command_confirm(resource)
53
+ return if resource["confirm"].nil? || !resource["input"].nil?
54
+ @commands << GirlsBar::Command::Confirm.new(resource["confirm"])
55
+ end
56
+
57
+ def add_command_redirect(resource)
58
+ return if resource["redirect_to"].nil?
59
+ @commands << GirlsBar::Command::Redirect.new(resource["redirect_to"])
60
+ end
61
+
62
+ def add_command_restart(resource)
63
+ return unless resource["input"].nil? && resource["confirm"].nil?
64
+ @commands << GirlsBar::Command::Restart.new
65
+ end
66
+ end
67
+
68
+ class Selection
69
+ attr :key, :label, :link
70
+
71
+ def initialize(key, label, link)
72
+ @key = GirlsBar::Filter.to_id key
73
+ @label = label
74
+ @link = GirlsBar::Filter.to_id link
75
+ end
76
+ end
77
+ end
@@ -6,27 +6,24 @@ module GirlsBar
6
6
  /^\d/ =~ param ? param.to_i : param.downcase.strip
7
7
  end
8
8
 
9
- def self.to_subject(str, data)
10
- return replace_vars_from_data(str, data)
9
+ def self.to_subject(str)
10
+ return replace_vars_from_data(str)
11
11
  end
12
12
 
13
- def self.to_selection(str, data)
14
- return replace_vars_from_data(str, data)
13
+ def self.to_selection(str)
14
+ return replace_vars_from_data(str)
15
15
  end
16
16
 
17
- def self.to_script(str, data)
18
- script = replace_vars_from_data(str, data)
17
+ def self.to_script(str)
18
+ script = replace_vars_from_data(str)
19
19
  script.split("\n").join(" && ")
20
20
  end
21
21
 
22
22
  private
23
-
24
- def self.replace_vars_from_data(str, data)
25
- unless data.empty?
26
- str.scan(/\{%(.+)?%\}/).flatten.map do |x|
27
- str.gsub!(/\{%#{x}%\}/, data[x.strip])
28
- end
29
- end
23
+ def self.replace_vars_from_data(str)
24
+ str.scan(/(\{\%\s*(\w+)?\s*%\})/).uniq.map {|match|
25
+ str.gsub!(/#{match[0]}/, "#{GirlsBar::Data.get(match[1])}")
26
+ } unless GirlsBar::Data.empty?
30
27
  return str
31
28
  end
32
29
  end
@@ -3,12 +3,11 @@ module GirlsBar
3
3
  module Helper
4
4
  def self.set_color(*arg)
5
5
  print color_codes(arg)
6
- yield
6
+ yield if block_given?
7
7
  print color_code(:clear)
8
8
  end
9
9
 
10
10
  private
11
-
12
11
  def self.color_code(key)
13
12
  "\e[#{GirlsBar::DISPLAY_COLORS[key]}m"
14
13
  end
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ class Router
4
+ def self.start
5
+ show_boot_message
6
+ show_banner unless GirlsBar::Settings.title.nil?
7
+ execute_start
8
+ end
9
+
10
+ def self.restart
11
+ execute_start
12
+ end
13
+
14
+ def self.quit
15
+ show_quit_message
16
+ exit
17
+ end
18
+
19
+ def self.help
20
+ show_help_message
21
+ end
22
+
23
+ def self.retry
24
+ show_retry_message
25
+ end
26
+
27
+ def self.move(id)
28
+ if next_entry = GirlsBar::Entry.all.find {|entry| entry.id == id }
29
+ next_entry.execute
30
+ else
31
+ show_invalid_link_message
32
+ execute_start
33
+ end
34
+ end
35
+
36
+ private
37
+ def self.execute_start
38
+ GirlsBar::Entry.first.execute
39
+ end
40
+
41
+ def self.show_boot_message
42
+ GirlsBar::Helper.set_color(:red) {
43
+ puts GirlsBar::Settings.boot_message
44
+ }
45
+ end
46
+
47
+ def self.show_quit_message
48
+ GirlsBar::Helper.set_color(:green) {
49
+ print "\n"
50
+ puts GirlsBar::Settings.quit_message
51
+ }
52
+ end
53
+
54
+ def self.show_help_message
55
+ GirlsBar::Helper.set_color(:green) {
56
+ print "\n"
57
+ puts GirlsBar::Settings.help_message
58
+ }
59
+ end
60
+
61
+ def self.show_retry_message
62
+ GirlsBar::Helper.set_color(:red) {
63
+ print "\n"
64
+ puts GirlsBar::Settings.retry_message
65
+ }
66
+ end
67
+
68
+ def self.show_invalid_link_message
69
+ GirlsBar::Helper.set_color(:red) {
70
+ print "\n"
71
+ puts GirlsBar::Settings.invalid_link_message
72
+ }
73
+ end
74
+
75
+ def self.show_banner
76
+ GirlsBar::Helper.set_color(:yellow) {
77
+ print [
78
+ nil,
79
+ GirlsBar::Settings.delimiter,
80
+ GirlsBar::Settings.title,
81
+ GirlsBar::Settings.delimiter,
82
+ GirlsBar::Settings.description
83
+ ].join("\n")
84
+ }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ module GirlsBar
3
+ class Settings
4
+ def self.setup(resource=nil)
5
+ resource ||= {}
6
+ @title = resource["title"]
7
+ @description = resource["description"]
8
+ @delimiter = set_delimiter(resource["delimiter"])
9
+ @prompt = resource["prompt"] || GirlsBar::DEFAULT_SETTINGS[:prompt]
10
+ @boot_message = GirlsBar::DEFAULT_SETTINGS[:messages][:boot]
11
+ @quit_message = GirlsBar::DEFAULT_SETTINGS[:messages][:quit]
12
+ @help_message = resource["help_message"] || @boot_message
13
+ @retry_message = GirlsBar::DEFAULT_SETTINGS[:messages][:retry]
14
+ @invalid_link_message = GirlsBar::DEFAULT_SETTINGS[:messages][:invalid_link]
15
+ instance_variables.each do |name|
16
+ self.define_singleton_method(name[1..-1]) { instance_variable_get(:"#{name}") }
17
+ end
18
+ end
19
+
20
+ private
21
+ def self.set_delimiter(resource=nil)
22
+ resource ||= {}
23
+ string = resource["character"] || GirlsBar::DEFAULT_SETTINGS[:delimiter][:character]
24
+ count = resource["count"] || GirlsBar::DEFAULT_SETTINGS[:delimiter][:count]
25
+ string * count
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
1
  # -*- utf-8 -*-
2
2
  module GirlsBar
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe "GirlsBar::Helper" do
5
+ describe "self.setcolor()" do
6
+ it 'ブロックを渡さなくても、正常に出力できる' do
7
+ expect { GirlsBar::Helper.set_color(:blue, :on_green) }.to output("\e[34;42m\e[0m").to_stdout
8
+ end
9
+
10
+ it 'ブロックを渡すと、ブロック内の処理が実行される' do
11
+ expect { GirlsBar::Helper.set_color(:red) { print "hello" } }.to output("\e[31mhello\e[0m").to_stdout
12
+ end
13
+
14
+ it '引数を渡さなくても、エラーにはならない' do
15
+ expect { GirlsBar::Helper.set_color }.to output("\e[m\e[0m").to_stdout
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ it 'has a version number' do
6
+ expect(GirlsBar::VERSION).not_to be nil
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GirlsBar do
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
+ require 'girls_bar'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girls_bar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Hirano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: pry
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +72,40 @@ dependencies:
58
72
  - - ">="
59
73
  - !ruby/object:Gem::Version
60
74
  version: 0.10.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: coveralls
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.7'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.7.3
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '0.7'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 0.7.3
95
+ - !ruby/object:Gem::Dependency
96
+ name: rdoc
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
61
109
  description: " Create interactive CLI program from YAML or JSON. "
62
110
  email:
63
111
  - yoshiyuki.hirano@henteco-labs.com
@@ -67,6 +115,7 @@ extensions: []
67
115
  extra_rdoc_files: []
68
116
  files:
69
117
  - ".gitignore"
118
+ - ".rspec"
70
119
  - Gemfile
71
120
  - LICENSE.txt
72
121
  - README.md
@@ -74,15 +123,34 @@ files:
74
123
  - bin/girls_bar
75
124
  - girls_bar.gemspec
76
125
  - lib/girls_bar.rb
77
- - lib/girls_bar/app.rb
78
- - lib/girls_bar/command.rb
79
- - lib/girls_bar/config.rb
126
+ - lib/girls_bar/command/confirm.rb
127
+ - lib/girls_bar/command/input.rb
128
+ - lib/girls_bar/command/redirect.rb
129
+ - lib/girls_bar/command/restart.rb
130
+ - lib/girls_bar/command/script.rb
80
131
  - lib/girls_bar/constants.rb
81
- - lib/girls_bar/controller.rb
132
+ - lib/girls_bar/data.rb
133
+ - lib/girls_bar/entry.rb
82
134
  - lib/girls_bar/filter.rb
83
135
  - lib/girls_bar/helper.rb
84
- - lib/girls_bar/model.rb
136
+ - lib/girls_bar/router.rb
137
+ - lib/girls_bar/settings.rb
85
138
  - lib/girls_bar/version.rb
139
+ - spec/girls_bar/command/confirm_spec.rb
140
+ - spec/girls_bar/command/input_spec.rb
141
+ - spec/girls_bar/command/redirect_spec.rb
142
+ - spec/girls_bar/command/restart_spec.rb
143
+ - spec/girls_bar/command/script_spec.rb
144
+ - spec/girls_bar/constants_spec.rb
145
+ - spec/girls_bar/data_spec.rb
146
+ - spec/girls_bar/entry_spec.rb
147
+ - spec/girls_bar/filter_spec.rb
148
+ - spec/girls_bar/helper_spec.rb
149
+ - spec/girls_bar/router_spec.rb
150
+ - spec/girls_bar/settings_spec.rb
151
+ - spec/girls_bar/version_spec.rb
152
+ - spec/girls_bar_spec.rb
153
+ - spec/spec_helper.rb
86
154
  homepage: https://github.com/YoshiyukiHirano/girls_bar
87
155
  licenses:
88
156
  - MIT
@@ -95,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
163
  requirements:
96
164
  - - ">="
97
165
  - !ruby/object:Gem::Version
98
- version: '0'
166
+ version: 1.9.3
99
167
  required_rubygems_version: !ruby/object:Gem::Requirement
100
168
  requirements:
101
169
  - - ">="
@@ -107,5 +175,20 @@ rubygems_version: 2.2.2
107
175
  signing_key:
108
176
  specification_version: 4
109
177
  summary: Create interactive CLI program from YAML or JSON.
110
- test_files: []
178
+ test_files:
179
+ - spec/girls_bar/command/confirm_spec.rb
180
+ - spec/girls_bar/command/input_spec.rb
181
+ - spec/girls_bar/command/redirect_spec.rb
182
+ - spec/girls_bar/command/restart_spec.rb
183
+ - spec/girls_bar/command/script_spec.rb
184
+ - spec/girls_bar/constants_spec.rb
185
+ - spec/girls_bar/data_spec.rb
186
+ - spec/girls_bar/entry_spec.rb
187
+ - spec/girls_bar/filter_spec.rb
188
+ - spec/girls_bar/helper_spec.rb
189
+ - spec/girls_bar/router_spec.rb
190
+ - spec/girls_bar/settings_spec.rb
191
+ - spec/girls_bar/version_spec.rb
192
+ - spec/girls_bar_spec.rb
193
+ - spec/spec_helper.rb
111
194
  has_rdoc:
data/lib/girls_bar/app.rb DELETED
@@ -1,28 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module GirlsBar
3
- class App
4
- attr_reader :controller, :config, :girls
5
- attr_accessor :data
6
-
7
- def self.boot(resource)
8
- app = self.new(resource)
9
- app.controller.start
10
- end
11
-
12
- def initialize(resource)
13
- @controller = GirlsBar::Controller.new(self)
14
- @config = GirlsBar::Config.new(resource['config'])
15
- @girls = []
16
- @data = {}
17
- register_girls resource['girls']
18
- end
19
-
20
- private
21
-
22
- def register_girls(resource)
23
- resource.each_pair do |res|
24
- girls << GirlsBar::Model::Girl.new(res)
25
- end
26
- end
27
- end
28
- end
@@ -1,130 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module GirlsBar
3
- module Command
4
- class Input
5
- def initialize(resource)
6
- @subject = resource['subject']
7
- @id = GirlsBar::Filter.to_id resource['id']
8
- @link = GirlsBar::Filter.to_id resource['link']
9
- end
10
-
11
- def execute(app)
12
- while true
13
- show_subject(app)
14
- raw_data = gets
15
- key = GirlsBar::Filter.to_id raw_data
16
- case key
17
- when 'exit', 'quit'
18
- app.controller.quit
19
- when 'help'
20
- app.controller.help
21
- else
22
- unless "#{key}".empty?
23
- app.data[@id] = raw_data.strip
24
- app.controller.move(@link)
25
- return true
26
- end
27
- end
28
- app.controller.retry
29
- end
30
- end
31
-
32
- private
33
-
34
- def show_subject(app)
35
- GirlsBar::Helper.set_color(:white) do
36
- print "\n"
37
- puts GirlsBar::Filter.to_subject(@subject, app.data)
38
- puts app.config.delimiter
39
- end
40
- print app.config.prompt
41
- end
42
- end
43
-
44
- class Confirm
45
- def initialize(resource)
46
- @subject = resource['subject']
47
- @selections = []
48
- register_selections resource['select']
49
- end
50
-
51
- def execute(app)
52
- while true
53
- show_subject_and_selections(app)
54
- key = GirlsBar::Filter.to_id gets
55
- case key
56
- when 'exit', 'quit'
57
- app.controller.quit
58
- when 'help'
59
- app.controller.help
60
- else
61
- if selected = find_selection_by_key(key)
62
- app.controller.move(selected.link)
63
- return true
64
- end
65
- end
66
- app.controller.retry
67
- end
68
- end
69
-
70
- private
71
-
72
- def register_selections(resource)
73
- resource.each do |id, content|
74
- @selections << GirlsBar::Model::Selection.new(id, content['label'], content['link'])
75
- end
76
- end
77
-
78
- def show_subject_and_selections(app)
79
- GirlsBar::Helper.set_color(:white) do
80
- print "\n"
81
- puts GirlsBar::Filter.to_subject(@subject, app.data)
82
- puts app.config.delimiter
83
- @selections.each do |selection|
84
- puts " #{selection.key}: " + GirlsBar::Filter.to_selection(selection.label, app.data)
85
- end
86
- puts app.config.delimiter
87
- end
88
- print app.config.prompt
89
- end
90
-
91
- def find_selection_by_key(key)
92
- @selections.find {|x| x.key == key }
93
- end
94
- end
95
-
96
- class Redirect
97
- def initialize(resource)
98
- @key = GirlsBar::Filter.to_id resource
99
- end
100
-
101
- def execute(app)
102
- app.controller.move(@key)
103
- end
104
- end
105
-
106
- class Restart
107
- def execute(app)
108
- app.controller.restart
109
- end
110
- end
111
-
112
- class Script
113
- def initialize(resource)
114
- @script = resource
115
- end
116
-
117
- def execute(app)
118
- script = GirlsBar::Filter.to_script(@script, app.data)
119
- GirlsBar::Helper.set_color(:green) do
120
- print "\n"
121
- puts "=> run #{script}"
122
- end
123
- res = %x( #{script} )
124
- GirlsBar::Helper.set_color(:blue) do
125
- puts res
126
- end
127
- end
128
- end
129
- end
130
- end
@@ -1,36 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module GirlsBar
3
- class Config
4
- attr :title,
5
- :description,
6
- :delimiter,
7
- :prompt,
8
- :boot_message,
9
- :quit_message,
10
- :help_message,
11
- :retry_message,
12
- :invalid_link_message
13
-
14
- def initialize(resource=nil)
15
- resource ||= {}
16
- @title = resource['title']
17
- @description = resource['description']
18
- @delimiter = set_delimiter(resource['delimiter'])
19
- @prompt = resource['prompt'] || GirlsBar::DEFAULT_SETTINGS[:prompt]
20
- @boot_message = GirlsBar::DEFAULT_SETTINGS[:messages][:boot]
21
- @quit_message = GirlsBar::DEFAULT_SETTINGS[:messages][:quit]
22
- @help_message = resource['help_message'] || @boot_message
23
- @retry_message = GirlsBar::DEFAULT_SETTINGS[:messages][:retry]
24
- @invalid_link_message = GirlsBar::DEFAULT_SETTINGS[:messages][:invalid_link]
25
- end
26
-
27
- private
28
-
29
- def set_delimiter(resource=nil)
30
- resource ||= {}
31
- string = resource['character'] || GirlsBar::DEFAULT_SETTINGS[:delimiter][:character]
32
- count = resource['count'] || GirlsBar::DEFAULT_SETTINGS[:delimiter][:count]
33
- string * count
34
- end
35
- end
36
- end
@@ -1,92 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module GirlsBar
3
- class Controller
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def start
9
- show_boot_message
10
- show_banner unless @app.config.title.nil?
11
- execute_start
12
- end
13
-
14
- def restart
15
- execute_start
16
- end
17
-
18
- def quit
19
- show_quit_message
20
- exit
21
- end
22
-
23
- def help
24
- show_help_message
25
- end
26
-
27
- def retry
28
- show_retry_message
29
- end
30
-
31
- def move(id)
32
- if next_girl = @app.girls.find {|g| g.id == id }
33
- next_girl.execute(@app)
34
- else
35
- show_invalid_link_message
36
- execute_start
37
- end
38
- end
39
-
40
- private
41
-
42
- def execute_start
43
- @app.girls.first.execute(@app)
44
- end
45
-
46
- def show_boot_message
47
- GirlsBar::Helper.set_color(:red) do
48
- puts @app.config.boot_message
49
- end
50
- end
51
-
52
- def show_quit_message
53
- GirlsBar::Helper.set_color(:green) do
54
- print "\n"
55
- puts @app.config.quit_message
56
- end
57
- end
58
-
59
- def show_help_message
60
- GirlsBar::Helper.set_color(:green) do
61
- print "\n"
62
- puts @app.config.help_message
63
- end
64
- end
65
-
66
- def show_retry_message
67
- GirlsBar::Helper.set_color(:red) do
68
- print "\n"
69
- puts @app.config.retry_message
70
- end
71
- end
72
-
73
- def show_invalid_link_message
74
- GirlsBar::Helper.set_color(:red) do
75
- print "\n"
76
- puts @app.config.invalid_link_message
77
- end
78
- end
79
-
80
- def show_banner
81
- GirlsBar::Helper.set_color(:yellow) do
82
- print [
83
- nil,
84
- @app.config.delimiter,
85
- @app.config.title,
86
- @app.config.delimiter,
87
- @app.config.description
88
- ].join("\n")
89
- end
90
- end
91
- end
92
- end
@@ -1,63 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module GirlsBar
3
- module Model
4
- class Girl
5
- attr :id
6
-
7
- def initialize(resource)
8
- @id = GirlsBar::Filter.to_id resource[0]
9
- @commands = []
10
- register_commands resource[1]
11
- end
12
-
13
- def execute(app)
14
- @commands.map {|x| x.execute(app) }
15
- end
16
-
17
- private
18
-
19
- def register_commands(resource)
20
- add_command_script resource
21
- add_command_input resource
22
- add_command_confirm resource
23
- add_command_redirect resource
24
- add_command_restart resource
25
- end
26
-
27
- def add_command_script(resource)
28
- return if resource['script'].nil?
29
- @commands << GirlsBar::Command::Script.new(resource['script'])
30
- end
31
-
32
- def add_command_input(resource)
33
- return if resource['input'].nil?
34
- @commands << GirlsBar::Command::Input.new(resource['input'])
35
- end
36
-
37
- def add_command_confirm(resource)
38
- return if resource['confirm'].nil? || !resource['input'].nil?
39
- @commands << GirlsBar::Command::Confirm.new(resource['confirm'])
40
- end
41
-
42
- def add_command_redirect(resource)
43
- return if resource['redirect_to'].nil?
44
- @commands << GirlsBar::Command::Redirect.new(resource['redirect_to'])
45
- end
46
-
47
- def add_command_restart(resource)
48
- return unless resource['input'].nil? && resource['confirm'].nil?
49
- @commands << GirlsBar::Command::Restart.new
50
- end
51
- end
52
-
53
- class Selection
54
- attr :key, :label, :link
55
-
56
- def initialize(key, label, link)
57
- @key = GirlsBar::Filter.to_id key
58
- @label = label
59
- @link = GirlsBar::Filter.to_id link
60
- end
61
- end
62
- end
63
- end