demojify 0.1.0

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
+ SHA256:
3
+ metadata.gz: 3fa95ee80a108bdd450763d20a5d389d0502d6a154010b74357303c9fc9784c4
4
+ data.tar.gz: f9d78083e9f669ae3445097f3e76474f9caee874418fddedc86056d0af833f68
5
+ SHA512:
6
+ metadata.gz: fb082e48290b61914d0500d0dea0b50591bdf6b783a235c03424eba6c97601325c29e4164480df4f40b65f09466329b9b268deac9d0e40a27f9d0a5b7f8b6d6f
7
+ data.tar.gz: 8ce43df0ef855742a4edb09806d9e5165330cc420df66eb59eaadce52456b29b2b5cb081f90d4ce55ac705c53c937af0c0ee512791e34b8934c09fbd3db24191
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Thomas Powell
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # demojify
2
+
3
+ A Ruby gem to convert all emoji in script files to ASCII-friendly text representations in the format `[emoji_name]`.
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ ```bash
10
+ gem install demojify
11
+ ```
12
+
13
+ Or add it to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'demojify'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Command Line
22
+
23
+ Convert emoji in all script files in the current directory and subdirectories:
24
+
25
+ ```bash
26
+ demojify
27
+ ```
28
+
29
+ Convert emoji in a specific directory:
30
+
31
+ ```bash
32
+ demojify /path/to/project
33
+ ```
34
+
35
+ Preview changes without modifying files (dry-run mode):
36
+
37
+ ```bash
38
+ demojify --dry-run
39
+ ```
40
+
41
+ Show help:
42
+
43
+ ```bash
44
+ demojify --help
45
+ ```
46
+
47
+ ### In Ruby Code
48
+
49
+ ```ruby
50
+ require 'demojify'
51
+
52
+ # Convert emoji in text
53
+ text = "Hello 😀 World 🚀"
54
+ result = Demojify::Converter.convert(text)
55
+ # => "Hello [grinning] World [rocket]"
56
+
57
+ # Process files in a directory
58
+ processor = Demojify::Processor.new(root_dir: ".", dry_run: false)
59
+ result = processor.process!
60
+ # => { total: 10, changed: 3 }
61
+ ```
62
+
63
+ ## Supported File Types
64
+
65
+ The gem processes the following script file types:
66
+ - Ruby (`.rb`)
67
+ - Python (`.py`)
68
+ - JavaScript (`.js`, `.jsx`)
69
+ - TypeScript (`.ts`, `.tsx`)
70
+ - Shell scripts (`.sh`, `.bash`, `.zsh`)
71
+ - Perl (`.pl`)
72
+ - PHP (`.php`)
73
+ - Java (`.java`)
74
+ - C/C++ (`.c`, `.cpp`, `.h`, `.hpp`)
75
+ - Go (`.go`)
76
+ - Rust (`.rs`)
77
+
78
+ ## How It Works
79
+
80
+ The gem:
81
+ 1. Recursively scans the specified directory for script files
82
+ 2. Reads each file and detects emoji characters
83
+ 3. Converts emoji to their text representation: `😀` → `[grinning]`
84
+ 4. Writes the modified content back to the file (unless in dry-run mode)
85
+
86
+ ## Development
87
+
88
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests.
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stringsn88keys/demojify.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
data/bin/demojify ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/demojify"
5
+
6
+ # Parse command line arguments
7
+ dry_run = ARGV.include?("--dry-run") || ARGV.include?("-n")
8
+ show_help = ARGV.include?("--help") || ARGV.include?("-h")
9
+
10
+ if show_help
11
+ puts "Usage: demojify [OPTIONS] [DIRECTORY]"
12
+ puts ""
13
+ puts "Convert all emoji in script files to [alt text] format."
14
+ puts ""
15
+ puts "Options:"
16
+ puts " -n, --dry-run Show what would be changed without modifying files"
17
+ puts " -h, --help Show this help message"
18
+ puts ""
19
+ puts "Arguments:"
20
+ puts " DIRECTORY Directory to process (default: current directory)"
21
+ puts ""
22
+ puts "Examples:"
23
+ puts " demojify # Process current directory"
24
+ puts " demojify --dry-run # Preview changes without modifying files"
25
+ puts " demojify /path/to/project # Process specific directory"
26
+ exit 0
27
+ end
28
+
29
+ # Get directory argument (filter out flags)
30
+ dir = ARGV.find { |arg| !arg.start_with?("-") } || "."
31
+
32
+ puts "Demojify v#{Demojify::VERSION}"
33
+ puts "Processing scripts in: #{File.expand_path(dir)}"
34
+ puts "(Dry run mode)" if dry_run
35
+ puts ""
36
+
37
+ processor = Demojify::Processor.new(root_dir: dir, dry_run: dry_run)
38
+ result = processor.process!
39
+
40
+ puts ""
41
+ puts "Summary:"
42
+ puts " Files processed: #{result[:total]}"
43
+ puts " Files changed: #{result[:changed]}"
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gemoji"
4
+
5
+ module Demojify
6
+ # Converts emoji to ASCII-friendly text representations
7
+ class Converter
8
+ # Convert all emoji in text to [alt text] format
9
+ # @param text [String] the text to convert
10
+ # @return [String] text with emoji replaced by [alt text]
11
+ def self.convert(text)
12
+ result = text.dup
13
+
14
+ # Get all emoji from gemoji library, sorted by length (longest first)
15
+ # This ensures we match longer emoji sequences before shorter ones
16
+ emoji_list = Emoji.all.sort_by { |e| -e.unicode_aliases.map(&:length).max }
17
+
18
+ emoji_list.each do |emoji|
19
+ # Try each unicode representation of the emoji
20
+ emoji.unicode_aliases.each do |unicode_char|
21
+ # Replace emoji with [name] format
22
+ result.gsub!(unicode_char, "[#{emoji.name}]")
23
+ end
24
+ end
25
+
26
+ result
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Demojify
4
+ # Processes files in a directory tree to convert emoji
5
+ class Processor
6
+ attr_reader :root_dir, :dry_run, :file_count, :changed_count
7
+
8
+ def initialize(root_dir: ".", dry_run: false)
9
+ @root_dir = File.expand_path(root_dir)
10
+ @dry_run = dry_run
11
+ @file_count = 0
12
+ @changed_count = 0
13
+ end
14
+
15
+ # Process all script files in the directory tree
16
+ def process!
17
+ find_script_files.each do |file_path|
18
+ process_file(file_path)
19
+ end
20
+
21
+ { total: @file_count, changed: @changed_count }
22
+ end
23
+
24
+ private
25
+
26
+ # Find all script files (ruby, python, javascript, shell, etc.)
27
+ def find_script_files
28
+ extensions = %w[.rb .py .js .sh .bash .zsh .pl .php .java .c .cpp .h .hpp .go .rs .ts .tsx .jsx]
29
+
30
+ Dir.glob(File.join(@root_dir, "**", "*")).select do |path|
31
+ File.file?(path) && extensions.any? { |ext| path.end_with?(ext) }
32
+ end
33
+ end
34
+
35
+ # Process a single file
36
+ def process_file(file_path)
37
+ @file_count += 1
38
+
39
+ # Read the file
40
+ original_content = File.read(file_path, encoding: "utf-8")
41
+
42
+ # Convert emoji
43
+ converted_content = Converter.convert(original_content)
44
+
45
+ # Check if content changed
46
+ if original_content != converted_content
47
+ @changed_count += 1
48
+
49
+ unless @dry_run
50
+ # Write back to file
51
+ File.write(file_path, converted_content, encoding: "utf-8")
52
+ end
53
+
54
+ puts "#{@dry_run ? '[DRY RUN] ' : ''}Converted: #{file_path}"
55
+ end
56
+ rescue => e
57
+ warn "Error processing #{file_path}: #{e.message}"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Demojify
4
+ VERSION = "0.1.0"
5
+ end
data/lib/demojify.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "demojify/version"
4
+ require_relative "demojify/converter"
5
+ require_relative "demojify/processor"
6
+
7
+ module Demojify
8
+ class Error < StandardError; end
9
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: demojify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - stringsn88keys
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gemoji
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ description: A gem to convert all emoji in scripts to their [alt text] equivalents
56
+ in ASCII-friendly characters
57
+ email:
58
+ - ''
59
+ executables:
60
+ - demojify
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - LICENSE
65
+ - README.md
66
+ - bin/demojify
67
+ - lib/demojify.rb
68
+ - lib/demojify/converter.rb
69
+ - lib/demojify/processor.rb
70
+ - lib/demojify/version.rb
71
+ homepage: https://github.com/stringsn88keys/demojify
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://github.com/stringsn88keys/demojify
76
+ source_code_uri: https://github.com/stringsn88keys/demojify
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.6.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.4.10
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Convert emoji to ASCII-friendly text representations
96
+ test_files: []