mobile_export 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f2871c8957e94d2fcecc96aac1a24dc0a52ca12
4
+ data.tar.gz: 585e3f3c2198162549fc6372584aed4da28163ee
5
+ SHA512:
6
+ metadata.gz: 8c7e61315aa21d7af1b553f465fa382d2619d75289fdcb82dbde564c14a5122326a267a91af275a6d77c60a0f24424bbb622497834bc4df022eca172f430ac2c
7
+ data.tar.gz: 21f9606524db98f0a563d88682257e9086376a5bf17cf7c0d7bb31cbf8c13ef8da0d1dc51828561161fdf54d932bbcd0180ed0ed98220384f0bc41ab52fe801d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mobile_export.gemspec
4
+ gemspec
5
+
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec", "~> 3.5.0"
9
+ gem "pry"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 JuanitoFatas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # MobileExport
2
+
3
+ Organize your images for Android.
4
+
5
+ Given:
6
+
7
+ ```
8
+ folder/
9
+ ├── base_h.png
10
+ ├── base_hhh.png
11
+ ├── base_m.png
12
+ ├── base_xh.png
13
+ └── base_xxh.png
14
+ ```
15
+
16
+ After `mobile_export`:
17
+
18
+ ```
19
+ folder/
20
+ ├── drawable-hdpi
21
+ │   └── base.png
22
+ ├── drawable-hhhdpi
23
+ │   └── base.png
24
+ ├── drawable-mdpi
25
+ │   └── base.png
26
+ ├── drawable-xhdpi
27
+ │   └── base.png
28
+ └── drawable-xxhdpi
29
+ └── base.png
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ $ gem install mobile_export
35
+
36
+ ## Usage
37
+
38
+ $ mobile_export
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JuanitoFatas/mobile_export.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mobile_export"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$"\n\t"
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Exit cleanly from an early interrupt
4
+ Signal.trap("INT") { abort }
5
+
6
+ require "rubygems"
7
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
8
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
9
+
10
+ require "mobile_export"
11
+ MobileExport::CLI.execute
@@ -0,0 +1,10 @@
1
+ require "mobile_export/version"
2
+ require "mobile_export/android"
3
+
4
+ module MobileExport
5
+ class CLI
6
+ def self.execute
7
+ Android.new.run
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,74 @@
1
+ require "pathname"
2
+ require "fileutils"
3
+
4
+ module MobileExport
5
+ class Android
6
+ def initialize(current_directory = Pathname.getwd)
7
+ @current_directory = Pathname(current_directory)
8
+ end
9
+
10
+ def run
11
+ create_directories!
12
+ move_images!
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :current_directory
18
+
19
+ SUFFIX_FOLDER = {
20
+ "hhh" => "drawable-hhhdpi",
21
+ "xxh" => "drawable-xxhdpi",
22
+ "xh" => "drawable-xhdpi",
23
+ "h" => "drawable-hdpi",
24
+ "m" => "drawable-mdpi",
25
+ }
26
+
27
+ IMAGE_EXTENSIONS = %w(png jpg jpeg)
28
+
29
+ private_constant :SUFFIX_FOLDER
30
+ private_constant :IMAGE_EXTENSIONS
31
+
32
+ def create_directories!
33
+ SUFFIX_FOLDER.values.each do |directory|
34
+ path = current_directory.join directory
35
+
36
+ FileUtils.mkdir_p(path) if !path.directory?
37
+ end
38
+ end
39
+
40
+ def image_patterns_for_glob
41
+ @_image_patterns_for_glob ||= begin
42
+ current_directory.join("*.{#{IMAGE_EXTENSIONS.join(",".freeze)}}").to_s
43
+ end
44
+ end
45
+
46
+ def image_patterns
47
+ @_image_patterns ||= Regexp.compile(IMAGE_EXTENSIONS.join("|".freeze))
48
+ end
49
+
50
+ def all_image_files
51
+ @_all_image_files = Dir[image_patterns_for_glob]
52
+ end
53
+
54
+ def move_images!
55
+ SUFFIX_FOLDER.each do |suffix, folder|
56
+ destination = current_directory.join(folder)
57
+ files_with_suffix = all_image_files.select do |file|
58
+ file =~ /_#{suffix}\.(#{image_patterns})$/
59
+ end
60
+
61
+ files_with_suffix.each do |file|
62
+ matched = Pathname(file).basename.to_s.match(
63
+ /(?<filename>.*)_(?<suffix>(#{suffix}))(?<extension>\..*)$/
64
+ )
65
+ old_path = file
66
+ new_path = destination.join(matched[:filename] + matched[:extension]).to_s
67
+
68
+ puts "Move #{old_path} to #{new_path}."
69
+ FileUtils.mv old_path, new_path
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module MobileExport
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mobile_export/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobile_export"
8
+ spec.version = MobileExport::VERSION
9
+ spec.authors = ["JuanitoFatas"]
10
+ spec.email = ["katehuang0320@gmail.com"]
11
+
12
+ spec.summary = %q{Organize image files for Mobile platform.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/JuanitoFatas/mobile_export"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobile_export
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JuanitoFatas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Organize image files for Mobile platform.
14
+ email:
15
+ - katehuang0320@gmail.com
16
+ executables:
17
+ - mobile_export
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - exe/mobile_export
31
+ - lib/mobile_export.rb
32
+ - lib/mobile_export/android.rb
33
+ - lib/mobile_export/version.rb
34
+ - mobile_export.gemspec
35
+ homepage: https://github.com/JuanitoFatas/mobile_export
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.6.4
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Organize image files for Mobile platform.
59
+ test_files: []
60
+ has_rdoc: