random_username 1.0 → 1.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 +4 -4
 - data/README.md +41 -3
 - data/lib/random_username.rb +8 -1
 - data/lib/random_username/version.rb +1 -1
 - data/test/test_random_username.rb +41 -4
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a675071998814bca647af20257e0ec2a73809f9c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7c9585857dfe4f97157dfc420474eddf858568c4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 352037dc4b567b4e7cf74a53713f26ac42acf6a3310ca84bf84d47a5022515616b65f5803971062bec939c4194300970752d55e081e784c84633a83bd9f3a548
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2c1c8990bb4fffefeb75e8db1f9ce2d0479a97c0f147ccc1a233866c9a94557ff3c8d7beea4ba22c4c7f376421f4156e2f113509e9a1c787b02098717dadc097
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,4 +1,42 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
            ===============
         
     | 
| 
      
 1 
     | 
    
         
            +
            # RandomUsername
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            A random Heroku-style name generator.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            # Installation
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                gem "random_username"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                $ gem install random_username
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                RandomUsername.noun
         
     | 
| 
      
 22 
     | 
    
         
            +
                => "sunrise"
         
     | 
| 
      
 23 
     | 
    
         
            +
                => "prize"
         
     | 
| 
      
 24 
     | 
    
         
            +
                => "sage"
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                RandomUsername.adjective
         
     | 
| 
      
 27 
     | 
    
         
            +
                => "heroic"
         
     | 
| 
      
 28 
     | 
    
         
            +
                => "worthy"
         
     | 
| 
      
 29 
     | 
    
         
            +
                => "enigmatic"
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                RandomUsername.username
         
     | 
| 
      
 32 
     | 
    
         
            +
                => "hollowlight"
         
     | 
| 
      
 33 
     | 
    
         
            +
                => "legitsunrise"
         
     | 
| 
      
 34 
     | 
    
         
            +
                => "earthyleaf"
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            1. Fork it
         
     | 
| 
      
 39 
     | 
    
         
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         
     | 
| 
      
 40 
     | 
    
         
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         
     | 
| 
      
 41 
     | 
    
         
            +
            4. Push to the branch (`git push origin my-new-feature`)
         
     | 
| 
      
 42 
     | 
    
         
            +
            5. Create new Pull Request
         
     | 
    
        data/lib/random_username.rb
    CHANGED
    
    | 
         @@ -1,6 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "random_username/version"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module RandomUsername
         
     | 
| 
      
 4 
     | 
    
         
            +
              RandomUsername::Error = Class.new(StandardError)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       4 
6 
     | 
    
         
             
              def self.adjective(options = {})
         
     | 
| 
       5 
7 
     | 
    
         
             
                get_item("adjectives", options)
         
     | 
| 
       6 
8 
     | 
    
         
             
              end
         
     | 
| 
         @@ -9,10 +11,15 @@ module RandomUsername 
     | 
|
| 
       9 
11 
     | 
    
         
             
                get_item("nouns", options)
         
     | 
| 
       10 
12 
     | 
    
         
             
              end
         
     | 
| 
       11 
13 
     | 
    
         | 
| 
      
 14 
     | 
    
         
            +
              def self.username(options = {})
         
     | 
| 
      
 15 
     | 
    
         
            +
                options[:max_length] /= 2 if options[:max_length]
         
     | 
| 
      
 16 
     | 
    
         
            +
                adjective(options) + noun(options)
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       12 
19 
     | 
    
         
             
              def self.get_item(filename, options = {})
         
     | 
| 
       13 
20 
     | 
    
         
             
                items = items_from_file(filename)
         
     | 
| 
       14 
21 
     | 
    
         
             
                items.select!{ |item| item.length <= options[:max_length] } if options[:max_length]
         
     | 
| 
       15 
     | 
    
         
            -
                items.sample
         
     | 
| 
      
 22 
     | 
    
         
            +
                items.sample || fail(RandomUsername::Error, "No words found")
         
     | 
| 
       16 
23 
     | 
    
         
             
              end
         
     | 
| 
       17 
24 
     | 
    
         | 
| 
       18 
25 
     | 
    
         
             
              def self.items_from_file(filename)
         
     | 
| 
         @@ -2,8 +2,18 @@ require "minitest/autorun" 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require "random_username"
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            class TestRandomUsername < Minitest::Test
         
     | 
| 
      
 5 
     | 
    
         
            +
              def all_adjectives
         
     | 
| 
      
 6 
     | 
    
         
            +
                @all_adjectives ||= RandomUsername.items_from_file("adjectives")
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def all_nouns
         
     | 
| 
      
 10 
     | 
    
         
            +
                @all_nouns ||= RandomUsername.items_from_file("nouns")
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
       5 
13 
     | 
    
         
             
              def test_adjective
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 14 
     | 
    
         
            +
                adjective = RandomUsername.adjective
         
     | 
| 
      
 15 
     | 
    
         
            +
                refute_empty adjective
         
     | 
| 
      
 16 
     | 
    
         
            +
                assert_includes all_adjectives, adjective
         
     | 
| 
       7 
17 
     | 
    
         
             
              end
         
     | 
| 
       8 
18 
     | 
    
         | 
| 
       9 
19 
     | 
    
         
             
              def test_adjective_max_length
         
     | 
| 
         @@ -12,11 +22,15 @@ class TestRandomUsername < Minitest::Test 
     | 
|
| 
       12 
22 
     | 
    
         
             
              end
         
     | 
| 
       13 
23 
     | 
    
         | 
| 
       14 
24 
     | 
    
         
             
              def test_adjective_invalid_max_length
         
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 25 
     | 
    
         
            +
                assert_raises RandomUsername::Error do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  RandomUsername.adjective(:max_length => 1)
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
       16 
28 
     | 
    
         
             
              end
         
     | 
| 
       17 
29 
     | 
    
         | 
| 
       18 
30 
     | 
    
         
             
              def test_noun
         
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
      
 31 
     | 
    
         
            +
                noun = RandomUsername.noun
         
     | 
| 
      
 32 
     | 
    
         
            +
                refute_empty noun
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_includes all_nouns, noun
         
     | 
| 
       20 
34 
     | 
    
         
             
              end
         
     | 
| 
       21 
35 
     | 
    
         | 
| 
       22 
36 
     | 
    
         
             
              def test_noun_max_length
         
     | 
| 
         @@ -25,6 +39,29 @@ class TestRandomUsername < Minitest::Test 
     | 
|
| 
       25 
39 
     | 
    
         
             
              end
         
     | 
| 
       26 
40 
     | 
    
         | 
| 
       27 
41 
     | 
    
         
             
              def test_noun_invalid_max_length
         
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
      
 42 
     | 
    
         
            +
                assert_raises RandomUsername::Error do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  RandomUsername.noun(:max_length => 1)
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              def test_username
         
     | 
| 
      
 48 
     | 
    
         
            +
                username = RandomUsername.username
         
     | 
| 
      
 49 
     | 
    
         
            +
                refute_empty username
         
     | 
| 
      
 50 
     | 
    
         
            +
                anchor = (2..username.length).detect do |i|
         
     | 
| 
      
 51 
     | 
    
         
            +
                  all_adjectives.include?(username[0..i])
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
                assert_includes all_adjectives, username[0..anchor]
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert_includes all_nouns, username[anchor+1..-1]
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              def test_username_max_length
         
     | 
| 
      
 58 
     | 
    
         
            +
                username = RandomUsername.username(:max_length => 10)
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert username.length <= 10
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              def test_username_invalid_max_length
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_raises RandomUsername::Error do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  RandomUsername.username(:max_length => 2)
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
       29 
66 
     | 
    
         
             
              end
         
     | 
| 
       30 
67 
     | 
    
         
             
            end
         
     |