aaq 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d97d8f9bcdcb551beb826b56ac19446d65ee049f31d65b8bbcf19e5a9e1e4f2
4
- data.tar.gz: c47cf6ae819cde7f8382590200bd75faf114745029662082d98c2bb46fbbd21a
3
+ metadata.gz: 57bbcba5eec32436dae30fe60a35aca0aff4d8fecf1fdd4931d3649233eaa292
4
+ data.tar.gz: ee4461f18cbbc7ea29470bad73c8083963a9e8db8a8b5799f0345964cda4ce3c
5
5
  SHA512:
6
- metadata.gz: e1efa723ac14dbf45d5cd5f2e3129d412d57025fdac3626cd590ffc68b865c4a7a60088017ffe1597a693cb8045010f068667205b5c66e97981bce1108c5627e
7
- data.tar.gz: d00cea0bb3ff14f9bdd8addb8e7030364d540de93242e23b84655eb1b7aa2e661e8ad41f97f29d2ae082ca10221c48ebbd7d0494b6c5acd7fcf9fe1adaf2751c
6
+ metadata.gz: bf280853a4c201fbe2b3aaff20b11bc263d2fec1116a0d6a5f8352983a17b056e4fe8a4580e7f46b7864ccd786e94cd7b67e4751f7868df38204e6d4dd5d21ad
7
+ data.tar.gz: 0d0addfad1db5c00cd1161322591e388f7f7b2192e593a130fcdaba454cec2349c9937e727a87a99ca40f4d0ef47ae19608287b97c7e9d946f04700b79cb8acb
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-07-16 06:42:25 +0900 using RuboCop version 0.58.1.
3
+ # on 2018-11-10 23:33:14 +0900 using RuboCop version 0.60.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -14,7 +14,7 @@ Metrics/AbcSize:
14
14
  # Configuration parameters: CountComments, ExcludedMethods.
15
15
  # ExcludedMethods: refine
16
16
  Metrics/BlockLength:
17
- Max: 60
17
+ Max: 61
18
18
 
19
19
  # Offense count: 1
20
20
  # Configuration parameters: CountComments.
@@ -22,21 +22,21 @@ Metrics/ClassLength:
22
22
  Max: 118
23
23
 
24
24
  # Offense count: 2
25
- # Configuration parameters: CountComments.
25
+ # Configuration parameters: CountComments, ExcludedMethods.
26
26
  Metrics/MethodLength:
27
27
  Max: 24
28
28
 
29
29
  # Offense count: 4
30
30
  # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
31
- # AllowedNames: io, id, to, by, on, in, at
32
- Naming/UncommunicativeMethodParamName:
31
+ # AllowedNames: io, id, to, by, on, in, at, ip, db
32
+ Naming/MethodParameterName:
33
33
  Exclude:
34
34
  - 'lib/aaq.rb'
35
35
 
36
36
  # Offense count: 1
37
37
  Security/Eval:
38
38
  Exclude:
39
- - 'bin/aaq'
39
+ - 'exe/aaq'
40
40
 
41
41
  # Offense count: 1
42
42
  Security/Open:
data/Dockerfile ADDED
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.7.1-alpine
2
+
3
+ ARG AAQ_VERSION="0.1.4"
4
+
5
+ RUN apk add --no-cache --virtual=build-deps gcc libc-dev make pkgconfig \
6
+ && apk add --no-cache imagemagick6 imagemagick6-dev imagemagick6-libs \
7
+ && gem install aaq -v ${AAQ_VERSION} \
8
+ && apk del --no-cache build-deps
9
+
10
+ WORKDIR /root
11
+
12
+ CMD ["echo", "[usage]: docker run --rm -v $(pwd):/root yskoht/aaq aaq [image] [--color]"]
13
+
data/README.md CHANGED
@@ -1,26 +1,26 @@
1
+
1
2
  # AAQ - Ascii Art Quine
2
3
 
3
- ```sh
4
- # Download sample image
5
- curl -O https://github-media-downloads.s3.amazonaws.com/Octocats.zip && unzip Octocats.zip
6
- aaq Octocat/Octocat.png --color
7
- ```
4
+ [![Gem Version](https://badge.fury.io/rb/aaq.svg)](https://badge.fury.io/rb/aaq)
5
+ [![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
8
6
 
9
- ## Installation
7
+ Create ascii art quine from image file.
10
8
 
11
- Add this line to your application's Gemfile:
9
+ ![Demo.gif](https://github.com/yskoht/aaq/raw/gif/demo.gif)
12
10
 
13
- ```ruby
14
- gem 'aaq'
15
- ```
11
+ ## Quick start with Docker
16
12
 
17
- And then execute:
13
+ You can try aaq easily with [yskoht/aaq](https://hub.docker.com/repository/docker/yskoht/aaq).
18
14
 
19
15
  ```sh
20
- $ bundle
16
+ # Download sample image
17
+ curl -O https://github-media-downloads.s3.amazonaws.com/Octocats.zip && unzip Octocats.zip
18
+
19
+ # Mount current directory to read image file
20
+ docker run --rm -v $(pwd):/root yskoht/aaq aaq Octocat/Octocat.png --color
21
21
  ```
22
22
 
23
- Or install it yourself as:
23
+ ## Installation
24
24
 
25
25
  ```sh
26
26
  $ gem install aaq
@@ -31,7 +31,7 @@ $ gem install aaq
31
31
  Simple quine.
32
32
 
33
33
  ```sh
34
- aaq Octocat/Octocat.png
34
+ aaq Octocat/Octocat.png
35
35
  ```
36
36
 
37
37
  Colorful quine.
@@ -52,7 +52,7 @@ Put `--color` option.
52
52
  aaq Octocat/Octocat.png | xargs -0 -J % ruby -e % '' --color
53
53
  ```
54
54
 
55
- In source code.
55
+ In your source code.
56
56
 
57
57
  ```ruby
58
58
  require 'aaq'
data/aaq.gemspec CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.16"
26
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "bundler", "~> 2.2.33"
26
+ spec.add_development_dependency "rake", "~> 12.3.3"
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
28
  spec.add_development_dependency "rubocop", "~> 0.58"
29
29
 
data/exe/aaq CHANGED
@@ -6,9 +6,33 @@ require 'optparse'
6
6
 
7
7
  Version = AAQ::VERSION
8
8
 
9
- opt = OptionParser.new
10
- opt.banner = 'Usage: bundle exec aaq [image] [--color]'
11
- opt.on('--color', 'output color ascii-art')
9
+ options = {}
10
+ opt = OptionParser.new do |o|
11
+ o.banner = 'Usage: bundle exec aaq [image] [--color]'
12
+ o.on('--color', 'Output color ascii-art')
13
+ o.on('--horizontal N', Integer, 'Number of horizontal pixels per character (default: 6)') do |n|
14
+ options[:horizontal] = n
15
+ end
16
+ o.on('--vertical N', Integer, 'Number of vertical pixels per character (default: 16)') do |n|
17
+ options[:vertical] = n
18
+ end
19
+ end
20
+
12
21
  args = opt.parse(ARGV)
22
+ if args.empty?
23
+ puts opt.help
24
+ exit
25
+ end
13
26
 
14
- eval AAQ::AAQ.new(args[0]).convert.to_s
27
+ begin
28
+ eval AAQ::AAQ.new(
29
+ args.first,
30
+ options: {
31
+ unit_horizontal: options[:horizontal],
32
+ unit_vertical: options[:vertical]
33
+ }
34
+ ).convert.to_s
35
+ rescue SyntaxError
36
+ warn 'Error: The output ascii art is too small to generate the complete code.'
37
+ warn 'A smaller value for the --horizontal or --vertical options might remove the error.'
38
+ end
data/lib/aaq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AAQ
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.5'
5
5
  end
data/lib/aaq.rb CHANGED
@@ -5,14 +5,16 @@ require 'set'
5
5
  require 'rmagick'
6
6
 
7
7
  module AAQ
8
- UNIT_W = 6
9
- UNIT_H = 14
8
+ UNIT_HORIZONTAL_DEFAULT = 6
9
+ UNIT_VERTICAL_DEFAULT = 14
10
10
 
11
11
  class AAQ
12
- attr_reader :img, :width, :height, :data, :code
12
+ attr_reader :img, :width, :height, :data, :code, :unit_horizontal, :unit_vertical
13
13
 
14
- def initialize(input_img)
14
+ def initialize(input_img, options: {})
15
15
  org_img = Magick::ImageList.new(input_img)
16
+ @unit_horizontal = options[:unit_horizontal] || UNIT_HORIZONTAL_DEFAULT
17
+ @unit_vertical = options[:unit_vertical] || UNIT_VERTICAL_DEFAULT
16
18
  @img, @width, @height = resize(org_img)
17
19
  end
18
20
 
@@ -73,6 +75,7 @@ module AAQ
73
75
  width.times do |w|
74
76
  i = h * width + w
75
77
  next if i < 10
78
+
76
79
  c += co if i >= c.size
77
80
  str += b.map { |x| x[i] }.include?(1) ? c[k += 1] : ' '
78
81
  end
@@ -85,18 +88,18 @@ module AAQ
85
88
  private
86
89
 
87
90
  def resize(org_img)
88
- w = org_img.columns / UNIT_W
89
- h = org_img.rows / UNIT_H
90
- [org_img.resize(w * UNIT_W, h * UNIT_H), w, h]
91
+ w = org_img.columns / @unit_horizontal
92
+ h = org_img.rows / @unit_vertical
93
+ [org_img.resize(w * @unit_horizontal, h * @unit_vertical), w, h]
91
94
  end
92
95
 
93
96
  def quantize
94
97
  memo = {}
95
98
 
96
99
  Array.new(height) do |h|
97
- y = h * UNIT_H
100
+ y = h * @unit_vertical
98
101
  Array.new(width) do |w|
99
- x = w * UNIT_W
102
+ x = w * @unit_horizontal
100
103
  to_256color(mode(x, y), memo)
101
104
  end
102
105
  end
@@ -104,8 +107,8 @@ module AAQ
104
107
 
105
108
  def mode(x, y)
106
109
  h = Hash.new(0)
107
- y.upto(y + UNIT_H) do |dy|
108
- x.upto(x + UNIT_W) do |dx|
110
+ y.upto(y + @unit_vertical) do |dy|
111
+ x.upto(x + @unit_horizontal) do |dx|
109
112
  h[img.pixel_color(dx, dy)] += 1
110
113
  end
111
114
  end
@@ -113,7 +116,7 @@ module AAQ
113
116
  end
114
117
 
115
118
  def to_256(pix)
116
- [pix.red / 257, pix.green / 257, pix.blue / 257]
119
+ [pix.red / 256, pix.green / 256, pix.blue / 256]
117
120
  end
118
121
 
119
122
  def to_256color(pix, memo)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aaq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - yskoht
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-16 00:00:00.000000000 Z
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.2.33
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 2.2.33
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.16'
83
- description:
83
+ description:
84
84
  email:
85
85
  - ysk.oht@gmail.com
86
86
  executables:
@@ -93,6 +93,7 @@ files:
93
93
  - ".rubocop.yml"
94
94
  - ".rubocop_todo.yml"
95
95
  - ".travis.yml"
96
+ - Dockerfile
96
97
  - Gemfile
97
98
  - LICENSE.txt
98
99
  - README.md
@@ -108,7 +109,7 @@ homepage: https://github.com/yskoht/aaq
108
109
  licenses:
109
110
  - MIT
110
111
  metadata: {}
111
- post_install_message:
112
+ post_install_message:
112
113
  rdoc_options: []
113
114
  require_paths:
114
115
  - lib
@@ -123,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.6
128
- signing_key:
127
+ rubygems_version: 3.0.3
128
+ signing_key:
129
129
  specification_version: 4
130
130
  summary: Create ascii art quine from image file
131
131
  test_files: []