somemoji 0.3.2 → 0.4.0

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
  SHA1:
3
- metadata.gz: cb3b0923dfa3d0f5b047e54028fc235ce6bc475a
4
- data.tar.gz: c00021c451b2482a7c1a559b90de99747208c8d4
3
+ metadata.gz: a5968df8d5cdd9d90f4ed13049765d15d1bc98df
4
+ data.tar.gz: 3809aa17d978c8a7569d03a3675833d5619b4de4
5
5
  SHA512:
6
- metadata.gz: 0fb106ddabc5900bc370c61a90a2af8bd37554e380fba0e64fd333ae8069c986d27c1fe0e978e339e73021457c09a4ae60c57b93c9521844dfb0466e0f7a1127
7
- data.tar.gz: 8efdff1491f24a93f517464eb058046813d6fb65f1914b07351f34e0e0c0bb2ed28c8fac50b9fdf7c120ad7397c8068038f691d2d0065c608a87a480802a121c
6
+ metadata.gz: ecf472874f03a6319c174b0e0366bae4e202014198ac0d3bac0f5e9ebbdd80cf8f49481da7dcab5b84519753340f4000a31edd4083d0248a9145009b5e6a52e5
7
+ data.tar.gz: 0bcd7d90ac15d8e35feb063e5e3b27e51ce8b9165de952f2f251f25bc5744269495b5f7f3157eaafb83db454370a3ee5e23a0e3a17854153b760a39920164c9f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.4.0
2
+
3
+ - Add `somemoji` executable to extract emoji images
4
+
1
5
  ## v0.3.2
2
6
 
3
7
  - Fix bug: nil.map raises error on no code_points emoji :bug:
data/README.md CHANGED
@@ -33,9 +33,25 @@ Or install it yourself as:
33
33
  gem install somemoji
34
34
  ```
35
35
 
36
- ## Documentation
36
+ ## Command line tool
37
37
 
38
- See API documentation at http://www.rubydoc.info/github/r7kamura/somemoji.
38
+ `somemoji` executable is bundled to extract images from each emoji provider.
39
+
40
+ ```
41
+ $ somemoji --help
42
+ Usage: somemoji extract [options]
43
+ -p, --provider (required) apple, emoji_one, noto, or twemoji
44
+ -d, --destination (required) directory path to locate extracted image files
45
+ -f, --format png or svg (default: png)
46
+ -s, --size Some providers have different size image files
47
+ -h, --help Display this help message
48
+ ```
49
+
50
+ To extract emojis from Twemoji to ./images/emoji directory, execute:
51
+
52
+ ```bash
53
+ somemoji extract --provider=twemoji --destination=./images/emoji
54
+ ```
39
55
 
40
56
  ## Use cases
41
57
 
@@ -107,3 +123,7 @@ class EmojiFilter < ::HTML::Pipeline::Filter
107
123
  end
108
124
  end
109
125
  ```
126
+
127
+ ## Documentation
128
+
129
+ See API documentation at http://www.rubydoc.info/github/r7kamura/somemoji.
data/exe/somemoji ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require "somemoji"
4
+
5
+ builder = Somemoji::CommandBuilder.new(ARGV)
6
+ command = builder.build
7
+ command.call
@@ -0,0 +1,24 @@
1
+ module Somemoji
2
+ class CommandBuilder
3
+ # @param argv [Array<String>]
4
+ def initialize(argv)
5
+ @argv = argv
6
+ end
7
+
8
+ # @return [Somemoji::Commands::BaseCommand]
9
+ def build
10
+ if command_line_arguments.valid?
11
+ ::Somemoji::Commands::ExtractCommand.new(command_line_arguments)
12
+ else
13
+ ::Somemoji::Commands::ErrorCommand.new(command_line_arguments)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ # @return [Somemoji::CommandLineArguments]
20
+ def command_line_arguments
21
+ @command_line_arguments ||= ::Somemoji::CommandLineArguments.new(@argv)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ module Somemoji
2
+ class CommandLineArguments
3
+ # @param argv [Array<String>]
4
+ def initialize(argv)
5
+ @argv = argv
6
+ end
7
+
8
+ # @return [String]
9
+ def destination
10
+ slop_parse_result[:destination]
11
+ end
12
+
13
+ # @return [String]
14
+ def error_message
15
+ slop_options.to_s
16
+ end
17
+
18
+ # @return [String, nil]
19
+ def format
20
+ slop_parse_result[:format]
21
+ end
22
+
23
+ # @return [String]
24
+ def provider_name
25
+ slop_parse_result[:provider]
26
+ end
27
+
28
+ # @return [Integer, nil]
29
+ def size
30
+ slop_parse_result[:size]
31
+ end
32
+
33
+ # @return [Boolean]
34
+ def valid?
35
+ command_name == "extract" && !slop_parse_result.nil?
36
+ end
37
+
38
+ private
39
+
40
+ # @return [String]
41
+ def command_name
42
+ @argv[0]
43
+ end
44
+
45
+ # @return [Slop::Options]
46
+ def slop_options
47
+ @slop_options ||= begin
48
+ slop_options = ::Slop::Options.new
49
+ slop_options.banner = "Usage: somemoji extract [options]"
50
+ slop_options.string "-p", "--provider", "(required) apple, emoji_one, noto, or twemoji"
51
+ slop_options.string "-d", "--destination", "(required) directory path to locate extracted image files"
52
+ slop_options.string "-f", "--format", "png or svg (default: png)"
53
+ slop_options.integer "-s", "--size", "Some providers have different size image files"
54
+ slop_options.bool "-h", "--help", "Display this help message"
55
+ slop_options
56
+ end
57
+ end
58
+
59
+ # @return [Slop::Result]
60
+ def slop_parse_result
61
+ @slop_parse_result ||= ::Slop::Parser.new(slop_options).parse(@argv)
62
+ rescue ::Slop::UnknownOption
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,21 @@
1
+ module Somemoji
2
+ module Commands
3
+ class BaseCommand
4
+ # @param command_line_arguments [Somemoji::CommandLineArguments]
5
+ def initialize(command_line_arguments)
6
+ @command_line_arguments = command_line_arguments
7
+ end
8
+
9
+ def call
10
+ raise ::NotImplementedError
11
+ end
12
+
13
+ private
14
+
15
+ # @return [Somemoji::CommandLineArguments]
16
+ def command_line_arguments
17
+ @command_line_arguments
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Somemoji
2
+ module Commands
3
+ class ErrorCommand < BaseCommand
4
+ def call
5
+ abort(command_line_arguments.error_message)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ module Somemoji
2
+ module Commands
3
+ class ExtractCommand < BaseCommand
4
+ def call
5
+ if emoji_extractor_class && command_line_arguments.destination
6
+ emoji_extractor_class.new(
7
+ destination: command_line_arguments.destination,
8
+ format: command_line_arguments.format,
9
+ size: command_line_arguments.size,
10
+ ).extract
11
+ else
12
+ abort(command_line_arguments.error_message)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ # @return [Class]
19
+ def emoji_extractor_class
20
+ case command_line_arguments.provider_name
21
+ when "apple"
22
+ ::Somemoji::EmojiExtractors::AppleEmojiExtractor
23
+ when "emoji_one"
24
+ ::Somemoji::EmojiExtractors::EmojiOneEmojiExtractor
25
+ when "noto"
26
+ ::Somemoji::EmojiExtractors::NotoEmojiExtractor
27
+ when "twemoji"
28
+ ::Somemoji::EmojiExtractors::TwemojiEmojiExtractor
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -9,7 +9,7 @@ module Somemoji
9
9
 
10
10
  # @note Implementation for Somemoji::EmojiExtractors::BaseEmojiExtractor
11
11
  def extract
12
- ::Emoji::Extractor.new(IMAGE_SIZE, @directory_path).extract!
12
+ ::Emoji::Extractor.new(IMAGE_SIZE, @destination).extract!
13
13
  end
14
14
  end
15
15
  end
@@ -3,12 +3,12 @@ require "fileutils"
3
3
  module Somemoji
4
4
  module EmojiExtractors
5
5
  class BaseEmojiExtractor
6
- # @param directory_path [String]
6
+ # @param destination [String]
7
7
  # @param format [String]
8
8
  # @param silence [Boolean]
9
9
  # @param size [Integer, nil]
10
- def initialize(format: nil, directory_path:, silence: nil, size: nil)
11
- @directory_path = directory_path
10
+ def initialize(format: nil, destination:, silence: nil, size: nil)
11
+ @destination = destination
12
12
  @format = format || "png"
13
13
  @silence = silence || false
14
14
  @size = size
@@ -21,7 +21,7 @@ module Somemoji
21
21
  private
22
22
 
23
23
  def make_directory
24
- ::FileUtils.mkdir_p(@directory_path)
24
+ ::FileUtils.mkdir_p(@destination)
25
25
  end
26
26
 
27
27
  def silence?
@@ -23,8 +23,8 @@ module Somemoji
23
23
  http.use_ssl = true
24
24
  response = http.get(find_remote_emoji_path(emoji))
25
25
  if response.code == "200"
26
- ::FileUtils.mkdir_p("#{@directory_path}/unicode")
27
- ::File.write("#{@directory_path}/#{emoji.base_path}.#{extension}", response.body)
26
+ ::FileUtils.mkdir_p("#{@destination}/unicode")
27
+ ::File.write("#{@destination}/#{emoji.base_path}.#{extension}", response.body)
28
28
  true
29
29
  else
30
30
  false
@@ -1,3 +1,3 @@
1
1
  module Somemoji
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/somemoji.rb CHANGED
@@ -1,4 +1,10 @@
1
1
  require "json"
2
+ require "slop"
3
+ require "somemoji/command_builder"
4
+ require "somemoji/command_line_arguments"
5
+ require "somemoji/commands/base_command"
6
+ require "somemoji/commands/error_command"
7
+ require "somemoji/commands/extract_command"
2
8
  require "somemoji/emoji_collection"
3
9
  require "somemoji/emoji"
4
10
  require "somemoji/emoji_extractors/base_emoji_extractor"
data/somemoji.gemspec CHANGED
@@ -15,12 +15,16 @@ Gem::Specification.new do |spec|
15
15
  f.match(%r{^(test|spec|features)/})
16
16
  end
17
17
 
18
- spec.required_ruby_version = ">= 2.1.0"
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}).map{ |f| File.basename(f) }
19
20
 
20
21
  spec.require_paths = ["lib"]
21
22
 
23
+ spec.required_ruby_version = ">= 2.1.0"
24
+
22
25
  spec.add_dependency "gemoji", "3.0.0.rc1"
23
26
  spec.add_dependency "json"
27
+ spec.add_dependency "slop", ">= 4.0.0"
24
28
  spec.add_development_dependency "bundler", "~> 1.13"
25
29
  spec.add_development_dependency "gemojione", "3.2.0"
26
30
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: somemoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2016-10-08 00:00:00.000000000 Z
12
12
  dependencies:
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +139,8 @@ dependencies:
125
139
  description:
126
140
  email:
127
141
  - r7kamura@gmail.com
128
- executables: []
142
+ executables:
143
+ - somemoji
129
144
  extensions: []
130
145
  extra_rdoc_files: []
131
146
  files:
@@ -1933,7 +1948,13 @@ files:
1933
1948
  - data/emoji_definitions/zzz.json
1934
1949
  - data/noto_supported_characters.json
1935
1950
  - data/twemoji_supported_characters.json
1951
+ - exe/somemoji
1936
1952
  - lib/somemoji.rb
1953
+ - lib/somemoji/command_builder.rb
1954
+ - lib/somemoji/command_line_arguments.rb
1955
+ - lib/somemoji/commands/base_command.rb
1956
+ - lib/somemoji/commands/error_command.rb
1957
+ - lib/somemoji/commands/extract_command.rb
1937
1958
  - lib/somemoji/emoji.rb
1938
1959
  - lib/somemoji/emoji_collection.rb
1939
1960
  - lib/somemoji/emoji_extractors/apple_emoji_extractor.rb