gruber-case 0.0.1
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 +15 -0
 - data/lib/gruber-case.rb +40 -0
 - metadata +44 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            !binary "U0hBMQ==":
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: !binary |-
         
     | 
| 
      
 4 
     | 
    
         
            +
                YTk5YzdmMzY4ZGYwY2YzY2U2YzMzMDIyMmZkZTcxOWFkMzUxYzk2ZA==
         
     | 
| 
      
 5 
     | 
    
         
            +
              data.tar.gz: !binary |-
         
     | 
| 
      
 6 
     | 
    
         
            +
                ZDQyMDdiYmE4M2EwOTFkMGE4MDA1ZWQzZWEwZDcxZTAzMTBiZTQ4Nw==
         
     | 
| 
      
 7 
     | 
    
         
            +
            !binary "U0hBNTEy":
         
     | 
| 
      
 8 
     | 
    
         
            +
              metadata.gz: !binary |-
         
     | 
| 
      
 9 
     | 
    
         
            +
                NTU0ZWUyMDI1M2M1MDVlOTI5MmRlYWE1ODJkZDBiMmExNzEzNzZhODhjYWE0
         
     | 
| 
      
 10 
     | 
    
         
            +
                ZmMwYzM1NzdmZTU5MjA4MDdkNzNlYzJmY2MyYWUwYjAzYjkyOGQ2YmI5OWMz
         
     | 
| 
      
 11 
     | 
    
         
            +
                Yjc2N2I2NGVhNmQzZDQ0ZmU4MGZiNTIwNmM2NDI4OTk5ZGIzZjA=
         
     | 
| 
      
 12 
     | 
    
         
            +
              data.tar.gz: !binary |-
         
     | 
| 
      
 13 
     | 
    
         
            +
                YTgyMzFmMGVmNzZmNWZlNDEwOTU0Yjc4ZDRjOWI1NjA2ZDI5M2E1OWY3MjA4
         
     | 
| 
      
 14 
     | 
    
         
            +
                NWJhYzdlOGVjNGVmZDA2NGVlNTdhNTJhMGExY2E4Yzk3NDMyMWUzOTMyYTRk
         
     | 
| 
      
 15 
     | 
    
         
            +
                YmYyMWE4YzQ5MTkzNjMzN2E4ZDA1MWY3NGQyZGZkNGZhY2VlZTY=
         
     | 
    
        data/lib/gruber-case.rb
    ADDED
    
    | 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class String
         
     | 
| 
      
 5 
     | 
    
         
            +
              def grubercase
         
     | 
| 
      
 6 
     | 
    
         
            +
                small_words = %w( a an and as at but by en for if in of on or the to v[.]? via vs[.]? )
         
     | 
| 
      
 7 
     | 
    
         
            +
                small_re = small_words.join('|')
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                line = ""
         
     | 
| 
      
 11 
     | 
    
         
            +
                self.split(/( [:.;?!][ ] | (?:[ ]|^)["“] )/x).each do |s|
         
     | 
| 
      
 12 
     | 
    
         
            +
                
         
     | 
| 
      
 13 
     | 
    
         
            +
                  s.gsub!(/ \b( [[:alpha:]] [[:lower:].'’]* )\b /x) do |w|
         
     | 
| 
      
 14 
     | 
    
         
            +
                    # Skip words with inline dots, e.g. "del.icio.us" or "example.com"
         
     | 
| 
      
 15 
     | 
    
         
            +
                    (w =~ / [[:alpha:]] [.] [[:alpha:]] /x) ? w : w.capitalize
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end #gsub!
         
     | 
| 
      
 17 
     | 
    
         
            +
                
         
     | 
| 
      
 18 
     | 
    
         
            +
                  # Lowercase our list of small words:
         
     | 
| 
      
 19 
     | 
    
         
            +
                  s.gsub!(/\b(#{small_re})\b/io) { |w| w.downcase }
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # If the first word in the title is a small word, then capitalize it:
         
     | 
| 
      
 22 
     | 
    
         
            +
                  s.gsub!(/\A([[:punct:]]*)(#{small_re})\b/io) { |w| $1 + $2.capitalize }
         
     | 
| 
      
 23 
     | 
    
         
            +
                
         
     | 
| 
      
 24 
     | 
    
         
            +
                  # If the last word in the title is a small word, then capitalize it:
         
     | 
| 
      
 25 
     | 
    
         
            +
                  s.gsub!(/\b(#{small_re})([[:punct:]]*)\Z/io) { |w| $1.capitalize + $2 }
         
     | 
| 
      
 26 
     | 
    
         
            +
                
         
     | 
| 
      
 27 
     | 
    
         
            +
                  # Append current substring to output
         
     | 
| 
      
 28 
     | 
    
         
            +
                  line += s
         
     | 
| 
      
 29 
     | 
    
         
            +
                
         
     | 
| 
      
 30 
     | 
    
         
            +
                end #each
         
     | 
| 
      
 31 
     | 
    
         
            +
              
         
     | 
| 
      
 32 
     | 
    
         
            +
                # Special Cases:
         
     | 
| 
      
 33 
     | 
    
         
            +
                line.gsub!(/ V(s?)\. /, ' v\1. ')               # "v." and "vs."
         
     | 
| 
      
 34 
     | 
    
         
            +
                line.gsub!(/(['’])S\b/, '\1s')                  # 'S (otherwise you get "the SEC'S decision")
         
     | 
| 
      
 35 
     | 
    
         
            +
                line.gsub!(/\b(AT&T|Q&A)\b/i) { |w| w.upcase }  # "AT&T" and "Q&A", which get tripped up by
         
     | 
| 
      
 36 
     | 
    
         
            +
                                                              # self-contained small words "at" and "a"
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                line
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: gruber-case
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Benjamin Jackson
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-10-01 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: A ruby port of John Gruber's Title Case algorithm
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: bhjackson@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 16 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            files:
         
     | 
| 
      
 19 
     | 
    
         
            +
            - lib/gruber-case.rb
         
     | 
| 
      
 20 
     | 
    
         
            +
            homepage: https://github.com/longform/gruber-case
         
     | 
| 
      
 21 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 22 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 23 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 24 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 25 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 26 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 27 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 28 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 31 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 33 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 34 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 35 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 36 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 37 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 38 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 39 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 40 
     | 
    
         
            +
            rubygems_version: 2.0.5
         
     | 
| 
      
 41 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 42 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 43 
     | 
    
         
            +
            summary: Gruber Case
         
     | 
| 
      
 44 
     | 
    
         
            +
            test_files: []
         
     |