flippy 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/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +93 -0
- data/Rakefile +1 -0
- data/bin/flippy +45 -0
- data/flippy.gemspec +22 -0
- data/lib/flippy.rb +60 -0
- data/lib/flippy/version.rb +3 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 kyoendo
|
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,93 @@
|
|
1
|
+
# Flippy
|
2
|
+
|
3
|
+
Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'flippy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install flippy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'flippy'
|
22
|
+
String.send(:include, Flippy)
|
23
|
+
|
24
|
+
flipped = "twitter".flip # => "ɹəʇʇᴉʍʇ"
|
25
|
+
flipped.unflip # => "twitter"
|
26
|
+
flipped_number = '1234567890'.flip # => "068L95ᔭεƧ⇂"
|
27
|
+
flipped_number.unflip # => "1234567890"
|
28
|
+
|
29
|
+
Try on multi line string.
|
30
|
+
|
31
|
+
code =<<CODE
|
32
|
+
# encoding: UTF-8
|
33
|
+
class Employee
|
34
|
+
attr_accessor :name, :title, :department
|
35
|
+
def initialize(name, title, department)
|
36
|
+
@name = name
|
37
|
+
@title = title
|
38
|
+
@department = department
|
39
|
+
end
|
40
|
+
|
41
|
+
def profile
|
42
|
+
"%s is %s at %s dept." % [name, title, department]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
charlie = Employee.new('Charlie', :programmer, :Game)
|
47
|
+
|
48
|
+
puts charlie.profile
|
49
|
+
CODE
|
50
|
+
|
51
|
+
puts flipped = code.flip
|
52
|
+
|
53
|
+
|
54
|
+
This produce following;
|
55
|
+
|
56
|
+
əlᴉɟoɹd˙əᴉlɹɐɥɔ sʇnd
|
57
|
+
|
58
|
+
(əɯɐ⅁: ‘ɹəɯɯɐɹɓoɹd: ‘'əᴉlɹɐɥƆ')ʍəu˙əəʎoldɯƎ = əᴉlɹɐɥɔ
|
59
|
+
|
60
|
+
puə
|
61
|
+
puə
|
62
|
+
[ʇuəɯʇɹɐdəp ‘əlʇᴉʇ ‘əɯɐu] % "˙ʇdəp s% ʇɐ s% sᴉ s%"
|
63
|
+
əlᴉɟoɹd ɟəp
|
64
|
+
|
65
|
+
puə
|
66
|
+
ʇuəɯʇɹɐdəp = ʇuəɯʇɹɐdəp@
|
67
|
+
əlʇᴉʇ = əlʇᴉʇ@
|
68
|
+
əɯɐu = əɯɐu@
|
69
|
+
(ʇuəɯʇɹɐdəp ‘əlʇᴉʇ ‘əɯɐu)əzᴉlɐᴉʇᴉuᴉ ɟəp
|
70
|
+
ʇuəɯʇɹɐdəp: ‘əlʇᴉʇ: ‘əɯɐu: ɹossəɔɔɐ‾ɹʇʇɐ
|
71
|
+
əəʎoldɯƎ ssɐlɔ
|
72
|
+
8-Ⅎ⊥Ո :ɓuᴉpoɔuə #
|
73
|
+
|
74
|
+
Try #unflip this again, then eval it. It will work.
|
75
|
+
|
76
|
+
Flippy.table output the mapping table.
|
77
|
+
|
78
|
+
## Thank you
|
79
|
+
|
80
|
+
Thank you to Fumiaki Nishihara for disclosing a ASCII mapping table for text upside down as his blog entry;
|
81
|
+
|
82
|
+
> twitter→ɹəʇʇɪʍʇのように英数字を180度回転して表示する方法|Colorless Green Ideas
|
83
|
+
> http://id.fnshr.info/2013/01/25/upsidedowntext/
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/flippy
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require_relative '../lib/flippy'
|
5
|
+
require "trollop"
|
6
|
+
|
7
|
+
class String
|
8
|
+
include Flippy
|
9
|
+
def ~
|
10
|
+
margin = scan(/^ +/).map(&:size).min
|
11
|
+
gsub(/^ {#{margin}}/, '')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class OptionParser
|
16
|
+
def self.parse!
|
17
|
+
Trollop::options do
|
18
|
+
version "flippy #{Flippy::VERSION} (c) 2013 kyoendo"
|
19
|
+
banner ~<<-EOS
|
20
|
+
Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
|
24
|
+
flippy [options] text
|
25
|
+
|
26
|
+
where [options] are:
|
27
|
+
EOS
|
28
|
+
|
29
|
+
opt :flip, "Flip given text", :default => true
|
30
|
+
opt :unflip, "Unflip given text"
|
31
|
+
opt :table, "Output flippy mapping table"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
opts = OptionParser.parse!
|
37
|
+
text = ARGV.join(' ')
|
38
|
+
|
39
|
+
puts begin
|
40
|
+
case
|
41
|
+
when opts[:table]; Flippy.table
|
42
|
+
when opts[:unflip]; text.unflip
|
43
|
+
when opts[:flip]; text.flip
|
44
|
+
end
|
45
|
+
end
|
data/flippy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flippy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "flippy"
|
8
|
+
gem.version = Flippy::VERSION
|
9
|
+
gem.authors = ["kyoendo"]
|
10
|
+
gem.email = ["postagie@gmail.com"]
|
11
|
+
gem.description = %q{Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".}
|
12
|
+
gem.summary = %q{Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".}
|
13
|
+
gem.homepage = "https://github.com/melborne/flippy"
|
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
|
+
gem.required_ruby_version = '>=1.9.3'
|
20
|
+
gem.add_dependency 'trollop'
|
21
|
+
# gem.add_development_dependency 'rspec'
|
22
|
+
end
|
data/lib/flippy.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
3
|
+
#
|
4
|
+
# Copyright (c) 2013 kyoendo / MIT License
|
5
|
+
#
|
6
|
+
# The table data is based on a following blog by Fumiaki Nishihara.
|
7
|
+
# twitter→ɹəʇʇɪʍʇのように英数字を180度回転して表示する方法|Colorless Green Ideas
|
8
|
+
# http://id.fnshr.info/2013/01/25/upsidedowntext/
|
9
|
+
|
10
|
+
require_relative "flippy/version"
|
11
|
+
|
12
|
+
module Flippy
|
13
|
+
T = [[65, 5572], [66, 5626], [67, 390], [68, 5601], [69, 398], [70, 8498], [71, 8513], [72, 72], [73, 73], [74, 5259], [75, 20012], [76, 8514], [77, 87], [78, 78], [79, 79], [80, 1280], [81, 908], [82, 7450], [83, 83], [84, 8869], [85, 1352], [86, 923], [87, 77], [88, 88], [89, 8516], [90, 90], [97, 592], [98, 113], [99, 596], [100, 112], [101, 601], [102, 607], [103, 595], [104, 613], [105, 7433], [106, 638], [107, 670], [108, 108], [109, 623], [110, 117], [111, 111], [112, 100], [113, 98], [114, 633], [115, 115], [116, 647], [117, 110], [118, 652], [119, 653], [120, 120], [121, 654], [122, 122], [48, 48], [49, 8642], [50, 423], [51, 949], [52, 5421], [53, 53], [54, 57], [55, 76], [56, 56], [57, 54], [46, 729], [44, 8216], [45, 45], [58, 58], [59, 1563], [33, 161], [63, 191], [38, 8523], [40, 41], [41, 40], [60, 62], [62, 60], [91, 93], [93, 91], [95, 8254], [8254, 95], [123, 125], [125, 123], [8756, 8757], [8757, 8756]]
|
14
|
+
|
15
|
+
def self.table
|
16
|
+
T.map do |kv|
|
17
|
+
kv.map { |code| "%s(U+%04x)" % [code.chr('UTF-8'), code]}
|
18
|
+
.join(" => ")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def flip
|
23
|
+
flip_or_unflip { |chr| _flip chr }
|
24
|
+
end
|
25
|
+
|
26
|
+
def unflip
|
27
|
+
flip_or_unflip { |chr| _unflip chr }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def flip_or_unflip
|
32
|
+
margin chars.map { |chr| yield chr }.join.reverse
|
33
|
+
end
|
34
|
+
|
35
|
+
def _flip(chr)
|
36
|
+
_, code = T.assoc(chr.ord)
|
37
|
+
code ? code.chr('UTF-8') : chr
|
38
|
+
end
|
39
|
+
|
40
|
+
def _unflip(chr)
|
41
|
+
code, _ = T.rassoc(chr.ord)
|
42
|
+
code ? code.chr('UTF-8') : chr
|
43
|
+
end
|
44
|
+
|
45
|
+
def margin(str)
|
46
|
+
return str unless str.match(/\n|\r/)
|
47
|
+
max = 0
|
48
|
+
str.lines.tap { |ls| max = ls.map(&:size).max }
|
49
|
+
.map { |l| ' ' * (max-l.size) + l }.join
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if __FILE__ == $0
|
54
|
+
String.send(:include, Flippy)
|
55
|
+
|
56
|
+
flipped = "twitter".flip # => "ɹəʇʇᴉʍʇ"
|
57
|
+
flipped.unflip # => "twitter"
|
58
|
+
flipped_number = '1234567890'.flip # => "068L95ᔭεƧ⇂"
|
59
|
+
flipped_number.unflip # => "1234567890"
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flippy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kyoendo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: trollop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
31
|
+
email:
|
32
|
+
- postagie@gmail.com
|
33
|
+
executables:
|
34
|
+
- flippy
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/flippy
|
44
|
+
- flippy.gemspec
|
45
|
+
- lib/flippy.rb
|
46
|
+
- lib/flippy/version.rb
|
47
|
+
homepage: https://github.com/melborne/flippy
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.9.3
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.23
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Fippy makes a text upside down, like "twitter" to "ɹəʇʇᴉʍʇ".
|
71
|
+
test_files: []
|