tfhelps 0.1.2 → 0.1.4
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 +4 -4
 - data/README.md +2 -3
 - data/bin/tfhelps +45 -8
 - data/lib/tfhelps/version.rb +1 -1
 - data/lib/tfhelps.rb +13 -12
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 42004c17cf81e02984fa216af7e75423275b42a2b94c04e7ae5b39b924cdb5ca
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 14f669ae8053450a453e0afcb392dd355b72045457862ff2bec20b779361cbd4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 36e5d569f3726603313683a0f0f15681b2d11c73206a43cd9cf819283ad6a96776c46394bb9c1010b52d2a86f759738f6811d9c621e7f64ebc74729d18fe0e32
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 815497f7b9a6d4e61110cc57fd68b14565ef1299e5a73b17216d8903fcac265e04622bed79496a1b521aadd4d4bb344c81ff61c140182e12559104ce3e3757d6
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # TFHelps
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
            [](https://badge.fury.io/rb/tfhelps)
         
     | 
| 
       3 
3 
     | 
    
         
             
            > TFHelps is a command-line tool designed to format text files professionally and efficiently. Built primarily for **Helps Ministries**, it uses the Gemini API to clean up and structure text based on predefined formatting guidelines. This tool is ideal for anyone looking to automate the process of making text more readable and polished.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            ## Installation
         
     | 
| 
         @@ -18,8 +18,7 @@ Before using TFHelps, you need to obtain an API key from Google's AI Studio. Fol 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
            1. Visit Google AI Studio and sign in with your Google account.
         
     | 
| 
       20 
20 
     | 
    
         
             
            2. Generate an API key (free or paid, depending on your usage needs).
         
     | 
| 
       21 
     | 
    
         
            -
            3. Store the API key in your environment variables with the key GEMINI_API_KEY.
         
     | 
| 
       22 
     | 
    
         
            -
               Add the following line to your .bashrc, .zshrc, or equivalent shell configuration file:
         
     | 
| 
      
 21 
     | 
    
         
            +
            3. Store the API key in your environment variables with the key GEMINI_API_KEY. To achieve that, add the following line to your .bashrc, .zshrc, or equivalent shell configuration file:
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
23 
     | 
    
         
             
            ```bash
         
     | 
| 
       25 
24 
     | 
    
         
             
            export GEMINI_API_KEY="your_api_key_here"
         
     | 
    
        data/bin/tfhelps
    CHANGED
    
    | 
         @@ -8,7 +8,7 @@ if ARGV.empty? 
     | 
|
| 
       8 
8 
     | 
    
         
             
              exit 1
         
     | 
| 
       9 
9 
     | 
    
         
             
            end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
            input_path = ARGV.shift
         
     | 
| 
       12 
12 
     | 
    
         
             
            api_key = ENV["GEMINI_API_KEY"]
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            if api_key.nil?
         
     | 
| 
         @@ -16,15 +16,52 @@ if api_key.nil? 
     | 
|
| 
       16 
16 
     | 
    
         
             
              exit 1
         
     | 
| 
       17 
17 
     | 
    
         
             
            end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
            output_dir = "output"
         
     | 
| 
      
 20 
     | 
    
         
            +
            if ARGV.include?("--output-dir")
         
     | 
| 
      
 21 
     | 
    
         
            +
              index = ARGV.index("--output-dir")
         
     | 
| 
      
 22 
     | 
    
         
            +
              output_dir = ARGV[index + 1]
         
     | 
| 
      
 23 
     | 
    
         
            +
              ARGV.delete_at(index)
         
     | 
| 
      
 24 
     | 
    
         
            +
              ARGV.delete_at(index)
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            def process_file(input_file, output_file, api_key)
         
     | 
| 
      
 28 
     | 
    
         
            +
              input_text = File.read(input_file)
         
     | 
| 
      
 29 
     | 
    
         
            +
              formatted_text = Tfhelps.format(input_text, api_key)
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              if formatted_text
         
     | 
| 
      
 32 
     | 
    
         
            +
                File.write(output_file, formatted_text)
         
     | 
| 
      
 33 
     | 
    
         
            +
                puts "Formatted text written to #{output_file}"
         
     | 
| 
      
 34 
     | 
    
         
            +
                true
         
     | 
| 
      
 35 
     | 
    
         
            +
              else
         
     | 
| 
      
 36 
     | 
    
         
            +
                puts "Failed to format #{input_file}"
         
     | 
| 
      
 37 
     | 
    
         
            +
                false
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
| 
       20 
40 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
            if File.directory?(input_path)
         
     | 
| 
      
 42 
     | 
    
         
            +
              Dir.mkdir(output_dir) unless Dir.exist?(output_dir)
         
     | 
| 
       22 
43 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
              txt_files = Dir.glob(File.join(input_path, "*.txt"))
         
     | 
| 
       24 
45 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
            if  
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
              if txt_files.empty?
         
     | 
| 
      
 47 
     | 
    
         
            +
                puts "No .txt files found in #{input_path}"
         
     | 
| 
      
 48 
     | 
    
         
            +
                exit 1
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              puts "Processing #{txt_files.size} .txt files..."
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              txt_files.each do |input_file|
         
     | 
| 
      
 54 
     | 
    
         
            +
                output_file = File.join(output_dir, File.basename(input_file))
         
     | 
| 
      
 55 
     | 
    
         
            +
                process_file(input_file, output_file, api_key)
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              puts "All files processed. Output saved in #{output_dir}/"
         
     | 
| 
       28 
59 
     | 
    
         
             
            else
         
     | 
| 
       29 
     | 
    
         
            -
               
     | 
| 
      
 60 
     | 
    
         
            +
              unless File.exist?(input_path)
         
     | 
| 
      
 61 
     | 
    
         
            +
                puts "Input file does not exist: #{input_path}"
         
     | 
| 
      
 62 
     | 
    
         
            +
                exit 1
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              output_file = File.basename(input_path)
         
     | 
| 
      
 66 
     | 
    
         
            +
              process_file(input_path, output_file, api_key)
         
     | 
| 
       30 
67 
     | 
    
         
             
            end
         
     | 
    
        data/lib/tfhelps/version.rb
    CHANGED
    
    
    
        data/lib/tfhelps.rb
    CHANGED
    
    | 
         @@ -16,18 +16,19 @@ module Tfhelps 
     | 
|
| 
       16 
16 
     | 
    
         
             
                def format_text(text)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  prompt = <<~PRO
         
     | 
| 
       18 
18 
     | 
    
         
             
                    Format the following text into a professional and readable structure.
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
                    Follow these guidelines:
         
     | 
| 
      
 20 
     | 
    
         
            +
                    1. Combine sentences into a single paragraph if they are separated by a single empty line.
         
     | 
| 
      
 21 
     | 
    
         
            +
                    2. Create a new paragraph whenever there are two or more empty lines separating the text.
         
     | 
| 
      
 22 
     | 
    
         
            +
                    3. Ensure proper spacing, punctuation, and capitalization throughout the text.
         
     | 
| 
      
 23 
     | 
    
         
            +
                    4. Replace all curved (smart) double quotation marks (e.g., “ ”) with straight (normal) double quotation marks (").
         
     | 
| 
      
 24 
     | 
    
         
            +
                    5. Convert curved single quote (’) to a straight single quote (').
         
     | 
| 
      
 25 
     | 
    
         
            +
                    6. Convert double hyphens (--), spaced double hyphens (- -), double em dashes (——), or spaced double em dashes (— —) into a single em dash (—). Apply this only if they don’t appear at the start of a new line. Remove any surrounding spaces before or after the dash.
         
     | 
| 
      
 26 
     | 
    
         
            +
                    7. Do not modify underscores(_); leave them as is.
         
     | 
| 
      
 27 
     | 
    
         
            +
                    8. Do not add a title or any additional text content that is not present in the original text.
         
     | 
| 
      
 28 
     | 
    
         
            +
                    9. Transform any new line that begins with one or two hyphen characters (- or --) into a standardized bullet point format.
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    Text to format:
         
     | 
| 
      
 31 
     | 
    
         
            +
                    #{text}
         
     | 
| 
       31 
32 
     | 
    
         
             
                  PRO
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                  http = Net::HTTP.new(@url.host, @url.port)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: tfhelps
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Wuletaw Wonte
         
     | 
| 
       8 
8 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       9 
9 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       10 
     | 
    
         
            -
            date:  
     | 
| 
      
 10 
     | 
    
         
            +
            date: 1980-01-02 00:00:00.000000000 Z
         
     | 
| 
       11 
11 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       12 
12 
     | 
    
         
             
            description: |
         
     | 
| 
       13 
13 
     | 
    
         
             
              The Helps Text Formatter gem is a command-line tool designed for Helps Ministries to clean up and format text files using the power of Google's Gemini API.
         
     | 
| 
         @@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       51 
51 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       52 
52 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       53 
53 
     | 
    
         
             
            requirements: []
         
     | 
| 
       54 
     | 
    
         
            -
            rubygems_version: 3.6. 
     | 
| 
      
 54 
     | 
    
         
            +
            rubygems_version: 3.6.8
         
     | 
| 
       55 
55 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       56 
56 
     | 
    
         
             
            summary: 'Helps Text Formatter: AI-powered text formatting for Helps Ministries.'
         
     | 
| 
       57 
57 
     | 
    
         
             
            test_files: []
         
     |