dotmoji 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: def718bb42a5f5c5fc3a950df26228c89b1f9c9b
4
+ data.tar.gz: e0da9248c1be68d463ed6007f5fbf730de2a01f7
5
+ SHA512:
6
+ metadata.gz: 6d497ee0cefbabde8fe4d29bf5fb96b972633d05ce4d3279e0266fadbeab274f527e41c9464c6cb521a22d2c0222c33e4c82bece667642de792e9d49e6769f59
7
+ data.tar.gz: 73ebdc29ccf9df4739c009dd68aa43e8ebe5ea9a84162c2233943402495df5fe8f57e52277d0a2f572310216a93e06299e2c60f7d13f4f45c8336a4a527b4526
data/.gitignore ADDED
@@ -0,0 +1,25 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ vendor
24
+ .idea
25
+ *.iml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format d
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dotmoji.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 utahta
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,38 @@
1
+ # Dotmoji
2
+
3
+ Get the dot data from the character.
4
+
5
+ Using [misaki font](http://www.geocities.jp/littlimi/misaki.htm)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'dotmoji'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dotmoji
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'dotmoji'
25
+ data = Dotmoji.map_data('テスト')
26
+ ```
27
+
28
+ ```bash
29
+ $ dotmoji display -t テスト
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/utahta/dotmoji/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dotmoji ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
+ require 'dotmoji'
5
+ require 'dotmoji/console'
6
+
7
+ Dotmoji::Console.start(ARGV)
data/dotmoji.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dotmoji/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dotmoji"
8
+ spec.version = Dotmoji::VERSION
9
+ spec.authors = ["utahta"]
10
+ spec.email = ["labs.ninxit@gmail.com"]
11
+ spec.summary = %q{Get the dot data from the character}
12
+ spec.description = %q{Get the dot data from the character}
13
+ spec.homepage = "https://github.com/utahta/dotmoji"
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
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
24
+
25
+ spec.add_dependency 'rmagick', '~> 2.13.4'
26
+ spec.add_dependency 'thor', '~> 0.19.1'
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'thor'
2
+
3
+ module Dotmoji
4
+
5
+ class Console < Thor
6
+ desc "display [OPTION]", "display dot data"
7
+ option :text, type: :string, required: true, aliases: '-t', desc: 'text'
8
+ def display
9
+ str = options[:text]
10
+ data = Dotmoji.map_data(str)
11
+ data.each do |y|
12
+ y.each do |x|
13
+ print x == 1 ? '#' : ' '
14
+ end
15
+ print "\n"
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,95 @@
1
+ module Dotmoji
2
+
3
+ class Mapping
4
+ FONT = File.expand_path('misaki_gothic.ttf', __dir__)
5
+ POINTSIZE = 8
6
+
7
+ # get dot data
8
+ def get(str)
9
+ img = make_image(str)
10
+
11
+ data = Array.new(img.rows) { Array.new(img.columns) }
12
+
13
+ img.rows.times do |y|
14
+ img.columns.times do |x|
15
+ src = img.pixel_color(x, y)
16
+ data[y][x] = src.to_color == 'black' ? 1 : 0
17
+ end
18
+ end
19
+
20
+ trim(data) # two-dimensional array
21
+ end
22
+
23
+ private
24
+
25
+ def make_text()
26
+ text = Magick::Draw.new
27
+ text.font = FONT
28
+ text.pointsize = POINTSIZE
29
+ text
30
+ end
31
+
32
+ def make_image(str)
33
+ text = make_text
34
+ metrics = text.get_type_metrics(str)
35
+ img = Magick::Image.new(metrics.width, metrics.height)
36
+
37
+ text.annotate(img, 0,0,0,0, str) do
38
+ self.fill = 'black'
39
+ self.gravity = Magick::SouthEastGravity
40
+ self.text_antialias = false
41
+ end
42
+ img
43
+ end
44
+
45
+ def trim(data)
46
+ rows = data.size
47
+ columns = data[0].size
48
+
49
+ # top
50
+ rows.times do
51
+ selected = data[0].select {|val| val == 1 }
52
+ break unless selected.empty?
53
+ data.delete_at(0)
54
+ rows -= 1
55
+ end
56
+
57
+ # bottom
58
+ rows.times do
59
+ selected = data[-1].select {|val| val == 1 }
60
+ break unless selected.empty?
61
+ data.delete_at(-1)
62
+ rows -= 1
63
+ end
64
+
65
+ # left
66
+ columns.times do
67
+ selected = []
68
+ rows.times do |i|
69
+ selected << 1 if data[i][0] == 1
70
+ end
71
+ break unless selected.empty?
72
+ rows.times do |i|
73
+ data[i].delete_at(0)
74
+ end
75
+ columns -= 1
76
+ end
77
+
78
+ # right
79
+ columns.times do
80
+ selected = []
81
+ rows.times do |i|
82
+ selected << 1 if data[i][-1] == 1
83
+ end
84
+ break unless selected.empty?
85
+ rows.times do |i|
86
+ data[i].delete_at(-1)
87
+ end
88
+ columns -= 1
89
+ end
90
+
91
+ data
92
+ end
93
+ end
94
+
95
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ module Dotmoji
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dotmoji.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'RMagick'
2
+ require 'dotmoji/version'
3
+ require 'dotmoji/mapping'
4
+
5
+ module Dotmoji
6
+ module_function
7
+
8
+ def map_data(str)
9
+ Mapping.new.get(str)
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'rspec'
2
+
3
+ describe 'Dotmoji' do
4
+
5
+ context 'Mapping' do
6
+ it '文字列を渡すとマッピングされたデータが返ること' do
7
+ data = Dotmoji.map_data('テスト')
8
+ expect(data).to eq [[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]]
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ require 'dotmoji'
18
+
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
+ # For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotmoji
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - utahta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-18 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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rmagick
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.19.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.19.1
83
+ description: Get the dot data from the character
84
+ email:
85
+ - labs.ninxit@gmail.com
86
+ executables:
87
+ - dotmoji
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/dotmoji
98
+ - dotmoji.gemspec
99
+ - lib/dotmoji.rb
100
+ - lib/dotmoji/console.rb
101
+ - lib/dotmoji/mapping.rb
102
+ - lib/dotmoji/misaki_gothic.ttf
103
+ - lib/dotmoji/version.rb
104
+ - spec/dotmoji_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/utahta/dotmoji
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Get the dot data from the character
130
+ test_files:
131
+ - spec/dotmoji_spec.rb
132
+ - spec/spec_helper.rb