aaq 0.1.3 → 0.1.4

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: 719d27872f8a7e13baa7775cc795ce893de4d655516d92f5ec101fbc73c34e6c
4
- data.tar.gz: ade5d54ccd08bcc27ccc01a7ac509f538c78881c9be0d30b00ddea0a484fef13
3
+ metadata.gz: 984f9a4f75b626cbc70cc1ca2ab21193b0a0aff0ecb33a8c71ac5466a06b7960
4
+ data.tar.gz: 17f888ef742b94aa92cc26928b4032382a434d1f22a5eb282a2e04fa4479da82
5
5
  SHA512:
6
- metadata.gz: 76bf04cdb15ee9ff8ba2f546763ffe82264315064469292d7d54f116b3ea455598a5bd6dc8f212b6f264d5618caa2876f3630c92f9db9545c3fcd1b365632ab4
7
- data.tar.gz: f8d1c5ebe31bd3920e77aec42140787266516921a74924ffda848e5954348df7ea9f0cbdbea02b772d7a84774128002ff43ea7c5804435844d37abfc088a84fd
6
+ metadata.gz: 00c80e962f2a1136c481644d3c96a3c992823d4bcdd168454e67052ef452a9fab26e70875a730c1f8c3cf9e8984513f546ada2d078efa0f5390ecde62866c24a
7
+ data.tar.gz: d173231d1e5c3c1a655981cf5e1e597fd17370940012bf97a246977fd38ed115ce3caa41b5321393d1a6240b9fc5f534ac2ec8df9ff83262a9fbcc3d4276f7dd
@@ -29,7 +29,7 @@ Metrics/MethodLength:
29
29
  # Offense count: 4
30
30
  # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
31
31
  # AllowedNames: io, id, to, by, on, in, at, ip, db
32
- Naming/UncommunicativeMethodParamName:
32
+ Naming/MethodParameterName:
33
33
  Exclude:
34
34
  - 'lib/aaq.rb'
35
35
 
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.7.1-alpine
2
+
3
+ ARG AAQ_VERSION="0.1.3"
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
@@ -8,10 +8,16 @@ Create ascii art quine from image file.
8
8
 
9
9
  ![Demo.gif](https://github.com/yskoht/aaq/raw/gif/demo.gif)
10
10
 
11
+ ## Quick start with Docker
12
+
13
+ You can try aaq easily with [yskoht/aaq](https://hub.docker.com/repository/docker/yskoht/aaq).
14
+
11
15
  ```sh
12
16
  # Download sample image
13
17
  curl -O https://github-media-downloads.s3.amazonaws.com/Octocats.zip && unzip Octocats.zip
14
- aaq Octocat/Octocat.png --color
18
+
19
+ # Mount current directory to read image file
20
+ docker run --rm -v $(pwd):/root yskoht/aaq aaq Octocat/Octocat.png --color
15
21
  ```
16
22
 
17
23
  ## Installation
@@ -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.1.4"
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,13 +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')
12
- args = opt.parse(ARGV)
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
13
20
 
21
+ args = opt.parse(ARGV)
14
22
  if args.empty?
15
23
  puts opt.help
16
- else
17
- eval AAQ::AAQ.new(args[0]).convert.to_s
24
+ exit
25
+ end
26
+
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.'
18
38
  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
 
@@ -86,18 +88,18 @@ module AAQ
86
88
  private
87
89
 
88
90
  def resize(org_img)
89
- w = org_img.columns / UNIT_W
90
- h = org_img.rows / UNIT_H
91
- [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]
92
94
  end
93
95
 
94
96
  def quantize
95
97
  memo = {}
96
98
 
97
99
  Array.new(height) do |h|
98
- y = h * UNIT_H
100
+ y = h * @unit_vertical
99
101
  Array.new(width) do |w|
100
- x = w * UNIT_W
102
+ x = w * @unit_horizontal
101
103
  to_256color(mode(x, y), memo)
102
104
  end
103
105
  end
@@ -105,8 +107,8 @@ module AAQ
105
107
 
106
108
  def mode(x, y)
107
109
  h = Hash.new(0)
108
- y.upto(y + UNIT_H) do |dy|
109
- x.upto(x + UNIT_W) do |dx|
110
+ y.upto(y + @unit_vertical) do |dy|
111
+ x.upto(x + @unit_horizontal) do |dx|
110
112
  h[img.pixel_color(dx, dy)] += 1
111
113
  end
112
114
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AAQ
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yskoht
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-10 00:00:00.000000000 Z
11
+ date: 2020-09-22 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.1.4
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.1.4
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
@@ -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
@@ -123,8 +124,7 @@ 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
127
+ rubygems_version: 3.1.2
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Create ascii art quine from image file