kagami 0.0.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.
@@ -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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kagami.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 toooooooby
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,51 @@
1
+ # Kagami [![Build Status](https://travis-ci.org/toooooooby/kagami.png)](https://travis-ci.org/toooooooby/kagami)
2
+
3
+
4
+ A tool for mirroring text and ascii art.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'kagami'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install kagami
19
+
20
+ ## Usage
21
+
22
+ ```bash
23
+ $ kagami "Java and you >>>> Ruby <<<< The internet"
24
+ The internet >>> Ruby >>>> Java and you
25
+
26
+ $ kagami <<END
27
+ Firewall
28
+ ||
29
+ +--------+ +-------+ || The Internet
30
+ | server +--+ proxy +----||======☁=======
31
+ +--------+ +-------+ ||
32
+ ||
33
+ END
34
+ Firewall
35
+ ||
36
+ The Internet || +-------+ +--------+
37
+ =======☁======||----+ proxy +--+ server |
38
+ || +-------+ +--------+
39
+ ||
40
+
41
+ $ cat hoge.txt | kagami
42
+ (reversed hoge.txt every one line)
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:test]
4
+ task :test do
5
+ ruby "test/test_kagami.rb"
6
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require File.join(File.dirname(__FILE__), "../lib/kagami")
5
+
6
+ program = File.basename($PROGRAM_NAME)
7
+ USAGE = <<-EOD
8
+ usage: #{program} text
9
+
10
+ example:
11
+ $ #{program} "Java and you >>>> Ruby <<<< The internet"
12
+ The internet >>> Ruby >>>> Java and you
13
+
14
+ $ #{program} <<END
15
+ Firewall
16
+ ||
17
+ +--------+ +-------+ || The Internet
18
+ | server +--+ proxy +----||======☁=======
19
+ +--------+ +-------+ ||
20
+ ||
21
+ END
22
+ Firewall
23
+ ||
24
+ The Internet || +-------+ +--------+
25
+ =======☁======||----+ proxy +--+ server |
26
+ || +-------+ +--------+
27
+ ||
28
+
29
+ $ cat hoge.txt | #{program}
30
+ (reversed hoge.txt every one line)
31
+ EOD
32
+
33
+ # When no args on interactive shell
34
+ if $stdin.tty? && ARGV.empty?
35
+ puts USAGE
36
+ exit 1
37
+ end
38
+
39
+ # Fetch source text
40
+ source = ARGV.shift || ARGF.read
41
+
42
+ Kagami.run(source)
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kagami/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "kagami"
8
+ gem.version = Kagami::VERSION
9
+ gem.authors = ["toooooooby"]
10
+ gem.email = ["toby.net.info.mail+git@gmail.com"]
11
+ gem.description = %q{A tool for mirroring text and ascii art}
12
+ gem.summary = %q{A tool for mirroring text and ascii art}
13
+ gem.homepage = "https://github.com/toooooooby/kagami"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,39 @@
1
+ require "kagami/version"
2
+
3
+ module Kagami
4
+ class << self
5
+ def max_width(line)
6
+ return line.lines.map{|x| x.chomp.size}.max
7
+ end
8
+
9
+ def ljust(line)
10
+ width = max_width(line)
11
+ return line.lines.map{|x| x.chomp.ljust(width)}.join("\n")
12
+ end
13
+
14
+ def reversed(line)
15
+ return line.lines.map{|x| x.chomp.reverse}.join("\n")
16
+ end
17
+
18
+ def readable(line)
19
+ return line.gsub(/(\w+(:? \w+)*)/){|s| s.reverse}
20
+ end
21
+
22
+ def convert(line)
23
+ # Align string
24
+ aligned_line = ljust(line)
25
+
26
+ # Reverse
27
+ reversed_line = reversed(aligned_line)
28
+
29
+ # Rereverse readable words only!!!!!
30
+ readable_line = readable(reversed_line)
31
+
32
+ return readable_line
33
+ end
34
+
35
+ def run(source)
36
+ puts convert(source)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Kagami
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $VERBOSE = true
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride'
6
+ require 'kagami'
7
+
8
+ describe "Kagami" do
9
+ ONE_LINE_DATA = "The internet >>> Ruby >>>> Java and you"
10
+ MULTI_LINE_DATA = <<-EOD
11
+ Firewall
12
+ ||
13
+ +--------+ +-------+ || The Internet
14
+ | server +--+ proxy +----||======☁=======
15
+ +--------+ +-------+ ||
16
+ ||
17
+ EOD
18
+
19
+ it ".max_width" do
20
+ Kagami.max_width(ONE_LINE_DATA).must_equal 39
21
+ Kagami.max_width(MULTI_LINE_DATA).must_equal 41
22
+ end
23
+
24
+ it ".ljust" do
25
+ Kagami.ljust(ONE_LINE_DATA).must_equal ONE_LINE_DATA
26
+ Kagami.ljust(MULTI_LINE_DATA).must_equal <<-EOD.chomp
27
+ Firewall
28
+ ||
29
+ +--------+ +-------+ || The Internet
30
+ | server +--+ proxy +----||======☁=======
31
+ +--------+ +-------+ ||
32
+ ||
33
+ EOD
34
+ end
35
+
36
+ it ".reversed" do
37
+ Kagami.reversed(ONE_LINE_DATA).must_equal "uoy dna avaJ >>>> ybuR >>> tenretni ehT"
38
+ Kagami.reversed(MULTI_LINE_DATA).must_equal <<-EOD.chomp
39
+ llaweriF
40
+ ||
41
+ tenretnI ehT || +-------+ +--------+
42
+ =======☁======||----+ yxorp +--+ revres |
43
+ || +-------+ +--------+
44
+ ||
45
+ EOD
46
+ end
47
+
48
+ it ".readable_after_reverse" do
49
+ Kagami.readable(ONE_LINE_DATA).must_equal "tenretni ehT >>> ybuR >>>> uoy dna avaJ"
50
+ Kagami.readable(MULTI_LINE_DATA).must_equal <<-EOD
51
+ llaweriF
52
+ ||
53
+ +--------+ +-------+ || tenretnI ehT
54
+ | revres +--+ yxorp +----||======☁=======
55
+ +--------+ +-------+ ||
56
+ ||
57
+ EOD
58
+ end
59
+
60
+ it ".convert" do
61
+ Kagami.convert(ONE_LINE_DATA).must_equal "Java and you >>>> Ruby >>> The internet"
62
+ Kagami.convert(MULTI_LINE_DATA).must_equal <<-EOD.chomp
63
+ Firewall
64
+ ||
65
+ The Internet || +-------+ +--------+
66
+ =======☁======||----+ proxy +--+ server |
67
+ || +-------+ +--------+
68
+ ||
69
+ EOD
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kagami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - toooooooby
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A tool for mirroring text and ascii art
15
+ email:
16
+ - toby.net.info.mail+git@gmail.com
17
+ executables:
18
+ - kagami
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .travis.yml
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/kagami
29
+ - kagami.gemspec
30
+ - lib/kagami.rb
31
+ - lib/kagami/version.rb
32
+ - test/test_kagami.rb
33
+ homepage: https://github.com/toooooooby/kagami
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ segments:
46
+ - 0
47
+ hash: 3696552201687161659
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
55
+ - 0
56
+ hash: 3696552201687161659
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.23
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: A tool for mirroring text and ascii art
63
+ test_files:
64
+ - test/test_kagami.rb