kagami 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/kagami +42 -0
- data/kagami.gemspec +19 -0
- data/lib/kagami.rb +39 -0
- data/lib/kagami/version.rb +3 -0
- data/test/test_kagami.rb +71 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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
|
data/Rakefile
ADDED
data/bin/kagami
ADDED
@@ -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)
|
data/kagami.gemspec
ADDED
@@ -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
|
data/lib/kagami.rb
ADDED
@@ -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
|
data/test/test_kagami.rb
ADDED
@@ -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
|