shiritori 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2c256b3a11cc30c829520c07c82aa3f564b7008
4
+ data.tar.gz: 0d6f943e464b788049833111586e41df442566fc
5
+ SHA512:
6
+ metadata.gz: 0b2c8e0a2a3fecda1333dd5e0fa28ceee9a7b3b6a800a0d23292218a3a44732f607446c8ce1c1450d20ec40acc4d275b5f7417229562daaf37233639e0db142d
7
+ data.tar.gz: 824429645224337460c1843119e6ad3cc053041ce69f7d76520db1efbff040bab28fdc1e2a71d93689f0d4c4474ad2929072e79a2e0edb4ead25222ddfb26795
data/.gitignore ADDED
@@ -0,0 +1,35 @@
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
18
+
19
+ # Ignore junk file
20
+ shiritori-*/*
21
+ doc/
22
+ **/*.swp
23
+ *.swp
24
+ **/*~
25
+ *.*~
26
+ *~
27
+ db/schema.rb
28
+ public/assets/*
29
+ reports/pdfs/*
30
+ config/database.yml
31
+ /.ruby-version
32
+ .DS_Store
33
+ .project
34
+ .idea
35
+ .secret
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shiritori.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 siman-man
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.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Shiritori
2
+
3
+ Let's try to create too long method chain!
4
+
5
+ ## Installation
6
+
7
+ install it yourself as:
8
+
9
+ $ gem install shiritori
10
+
11
+ Let's start creation long method chain.
12
+
13
+ ## Rule
14
+
15
+ 1. You set first object.
16
+
17
+ 2. Input the method that object can use.
18
+ * You can not use the method that has been used once.
19
+ * Don't override or define new method.
20
+
21
+ 3. It continue until the method can not be input.
22
+
23
+ 4. Let's enjoy shiritori!
24
+
25
+
26
+ ## Usage
27
+
28
+ ```
29
+ % shiritori
30
+ Please input first object > "Hello"
31
+
32
+ +----------------------+
33
+ | Current method chain |
34
+ +----------------------+
35
+ | "Hello" |
36
+ +----------------------+
37
+
38
+ +---------------+----------------+
39
+ | Current Class | Current Object |
40
+ +---------------+----------------+
41
+ | String | "Hello" |
42
+ +---------------+----------------+
43
+
44
+ Please input next method > chars
45
+ Exec command "Hello".chars
46
+
47
+ +----------------------+
48
+ | Current method chain |
49
+ +----------------------+
50
+ | "Hello".chars |
51
+ +----------------------+
52
+
53
+ +---------------+---------------------------+
54
+ | Current Class | Current Object |
55
+ +---------------+---------------------------+
56
+ | Array | ["H", "e", "l", "l", "o"] |
57
+ +---------------+---------------------------+
58
+
59
+ Please input next method > first
60
+ Exec command ["H", "e", "l", "l", "o"].first
61
+
62
+ +----------------------+
63
+ | Current method chain |
64
+ +----------------------+
65
+ | "Hello".chars.first |
66
+ +----------------------+
67
+
68
+ +---------------+----------------+
69
+ | Current Class | Current Object |
70
+ +---------------+----------------+
71
+ | String | "H" |
72
+ +---------------+----------------+
73
+
74
+ Please input next method >
75
+ ```
76
+
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it ( https://github.com/[my-github-username]/shiritori/fork )
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/shiritori ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'shiritori'
4
+
5
+ Shiritori::Main.new
@@ -0,0 +1,17 @@
1
+ class String
2
+ def to_s
3
+ inspect
4
+ end
5
+ end
6
+
7
+ class NilClass
8
+ def to_s
9
+ "nil"
10
+ end
11
+ end
12
+
13
+ class Symbol
14
+ def to_s
15
+ inspect
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ module Shiritori
2
+ module SearchMethod
3
+ def get_all_method
4
+ @check_list = Hash.new(false)
5
+ @method_list = []
6
+
7
+ scan_method
8
+
9
+ @method_list
10
+ end
11
+
12
+ def singleton(klass)
13
+ class << klass; self end
14
+ end
15
+
16
+ def scan_method(klass = BasicObject)
17
+ @check_list[klass] = true
18
+ @method_list |= klass.instance_methods
19
+
20
+ ObjectSpace.each_object(singleton(klass)) do |subclass|
21
+ if klass != subclass
22
+ scan_method(subclass) unless @check_list[subclass]
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,79 @@
1
+ require 'pp'
2
+
3
+ module Shiritori
4
+ class Main
5
+ include SearchMethod
6
+ include View
7
+
8
+ EXIT_PATTERN = /(exit|quit)/.freeze
9
+ METHOD_PATTERN = /[\w|\?|\>|\<|\=|\!|\[|\[|\]|\*|\/|\+|\-|\^|\~]+/.freeze
10
+
11
+ def initialize
12
+ @all_method = get_all_method
13
+ @current_object = nil
14
+ @current_class = Object
15
+ @current_chain = []
16
+ init
17
+ run
18
+ end
19
+
20
+ def update
21
+ @current_class = @current_object.class
22
+ end
23
+
24
+ def init
25
+ $stdout.print "Please input first object > "
26
+ begin
27
+ str = $stdin.gets.chomp
28
+ @current_object = eval(str)
29
+ @current_chain << @current_object.inspect
30
+ rescue
31
+ new_line
32
+ $stdout.puts "Undefined object error"
33
+ end
34
+ update
35
+ end
36
+
37
+ def run
38
+ loop do
39
+ show
40
+ $stdout.print "Please input next method > "
41
+ method = $stdin.gets.chomp
42
+ method.sub!(/^\./,"")
43
+
44
+ if method_symbol = command_check(method, @current_object)
45
+ if @all_method.include?(method_symbol)
46
+ @all_method.delete(method_symbol)
47
+ @current_object = eval("#{[@current_object.to_s, method].join('.')}")
48
+ @current_chain << method
49
+ update
50
+ else
51
+ $stdout.puts "Already used method."
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def command_check(command, object)
58
+ method_name = command.scan(METHOD_PATTERN).first
59
+
60
+ case command
61
+ when EXIT_PATTERN
62
+ exit
63
+ else
64
+ begin
65
+ $stdout.puts "Exec command #{[object.to_s, command].join('.')}"
66
+
67
+ Thread.new do
68
+ eval("$SAFE = 3; #{[object.to_s, command].join('.')}")
69
+ end.join
70
+ rescue => ex
71
+ $stdout.puts ex.message
72
+ return false
73
+ end
74
+ end
75
+
76
+ method_name.to_sym
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Shiritori
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ module Shiritori
2
+ module View
3
+ PADDING = 2
4
+
5
+ def new_line(num = 0)
6
+ $stdout.puts "\n"*num
7
+ end
8
+
9
+ def show
10
+ new_line
11
+ chain = "#{@current_chain.join('.')}"
12
+ chain_size = [chain.size+PADDING, 22].max
13
+
14
+ $stdout.puts "+#{'-'*chain_size}+"
15
+ $stdout.puts "|#{"Current method chain".center(chain_size)}|"
16
+ $stdout.puts "+#{'-'*chain_size}+"
17
+ $stdout.puts "|#{@current_chain.join('.').center(chain_size)}|"
18
+ $stdout.puts "+#{'-'*chain_size}+"
19
+
20
+ cls = "#{@current_class}"
21
+ obj = "#{@current_object.inspect}"
22
+ cls_size = ["#{@current_class}".size, 13].max+PADDING
23
+ obj_size = ["#{@current_object.inspect}".size, 14].max+PADDING
24
+
25
+ new_line
26
+ $stdout.puts "+#{'-'*(cls_size)}+#{'-'*(obj_size)}+"
27
+ $stdout.puts "|#{"Current Class".center(cls_size)}|#{"Current Object".center(obj_size)}|"
28
+ $stdout.puts "+#{'-'*(cls_size)}+#{'-'*(obj_size)}+"
29
+ $stdout.puts "|#{cls.center(cls_size)}|#{obj.center(obj_size)}|"
30
+ $stdout.puts "+#{'-'*(cls_size)}+#{'-'*(obj_size)}+"
31
+ new_line
32
+ end
33
+ end
34
+ end
data/lib/shiritori.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "shiritori/version"
2
+ require 'shiritori/convert'
3
+ require 'shiritori/view'
4
+ require "shiritori/search_method"
5
+ require "shiritori/shiritori"
data/shiritori.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shiritori/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shiritori"
8
+ spec.version = Shiritori::VERSION
9
+ spec.authors = ["siman-man"]
10
+ spec.email = ["k128585@ie.u-ryukyu.ac.jp"]
11
+ spec.summary = %q{shiritori}
12
+ spec.description = %q{shiritori}
13
+ spec.homepage = "https://github.com/siman-man/shiritori"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shiritori
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - siman-man
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: shiritori
42
+ email:
43
+ - k128585@ie.u-ryukyu.ac.jp
44
+ executables:
45
+ - shiritori
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/shiritori
55
+ - lib/shiritori.rb
56
+ - lib/shiritori/convert.rb
57
+ - lib/shiritori/search_method.rb
58
+ - lib/shiritori/shiritori.rb
59
+ - lib/shiritori/version.rb
60
+ - lib/shiritori/view.rb
61
+ - shiritori.gemspec
62
+ homepage: https://github.com/siman-man/shiritori
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: shiritori
86
+ test_files: []