quotifier 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 +7 -0
- data/lib/quotifier.rb +49 -0
- metadata +45 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: f9e21a259729a93b21c29923f5c6d241b3029ce1
         | 
| 4 | 
            +
              data.tar.gz: fc3f6248e8f492e3caf750c267835f2f2e263316
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 8355f30f00ef0584d88815354383ce2e6ca8d6816021960b00082b41bd7c3cc426da8efcb5252af0be2c6f7efdb7609e1fef321e9829574fba18bec4deb8af6a
         | 
| 7 | 
            +
              data.tar.gz: 1d791ed47f507df38e567d8eac6b788e8f193727467aa5a2dbb0221f12982cd682b1eb35c41681f4205129139e6f5164f68997396639a2da192fa85586eef672
         | 
    
        data/lib/quotifier.rb
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Quotifier
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(app)
         | 
| 6 | 
            +
                    @app  = app
         | 
| 7 | 
            +
                    file = File.read("db.json")
         | 
| 8 | 
            +
                    @dictionnary = JSON.parse(file)
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def call(env)
         | 
| 12 | 
            +
                    status, headers, body = @app.call(env) 
         | 
| 13 | 
            +
                    
         | 
| 14 | 
            +
                    if headers['Content-Type'].include?'text/html'
         | 
| 15 | 
            +
                        [status, headers, quotify(body,headers)]
         | 
| 16 | 
            +
                    else
         | 
| 17 | 
            +
                        [status, headers, body] 
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def quotify(html,headers)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    string_html = html[0]
         | 
| 25 | 
            +
                    counter = 0
         | 
| 26 | 
            +
                    fresh_output = String.new
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    string_html.each_line do |line|  
         | 
| 29 | 
            +
                        random_mod = rand(1..10)
         | 
| 30 | 
            +
                        if counter % random_mod == 0
         | 
| 31 | 
            +
                            line += random_quote 
         | 
| 32 | 
            +
                        end
         | 
| 33 | 
            +
                        fresh_output << line
         | 
| 34 | 
            +
                        counter = counter + 1
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                    html[0] = fresh_output
         | 
| 37 | 
            +
                    headers['Content-Length'] = fresh_output.length.to_s
         | 
| 38 | 
            +
                    return html
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                def random_quote()
         | 
| 42 | 
            +
                random_author = rand(0..(@dictionnary['authors'].count-1))
         | 
| 43 | 
            +
                random_quote = rand(0..(@dictionnary['quotes'].count - 1))
         | 
| 44 | 
            +
                return "\t\"" + @dictionnary['quotes'][random_quote] + " - "+ @dictionnary['authors'][random_author] + "\"" + "\n"
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
             | 
| 48 | 
            +
             | 
| 49 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: quotifier
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Michel Chatmajian
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2017-12-30 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: 'Rack Middleware that inserts random quotes into outbound html being
         | 
| 14 | 
            +
              served from any Rack webserver '
         | 
| 15 | 
            +
            email: chamich196@hotmail.com
         | 
| 16 | 
            +
            executables: []
         | 
| 17 | 
            +
            extensions: []
         | 
| 18 | 
            +
            extra_rdoc_files: []
         | 
| 19 | 
            +
            files:
         | 
| 20 | 
            +
            - lib/quotifier.rb
         | 
| 21 | 
            +
            homepage: http://rubygems.org/gems/quotifier
         | 
| 22 | 
            +
            licenses:
         | 
| 23 | 
            +
            - MIT
         | 
| 24 | 
            +
            metadata: {}
         | 
| 25 | 
            +
            post_install_message: 
         | 
| 26 | 
            +
            rdoc_options: []
         | 
| 27 | 
            +
            require_paths:
         | 
| 28 | 
            +
            - lib
         | 
| 29 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
              requirements:
         | 
| 31 | 
            +
              - - ">="
         | 
| 32 | 
            +
                - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                  version: '0'
         | 
| 34 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 35 | 
            +
              requirements:
         | 
| 36 | 
            +
              - - ">="
         | 
| 37 | 
            +
                - !ruby/object:Gem::Version
         | 
| 38 | 
            +
                  version: '0'
         | 
| 39 | 
            +
            requirements: []
         | 
| 40 | 
            +
            rubyforge_project: 
         | 
| 41 | 
            +
            rubygems_version: 2.6.14
         | 
| 42 | 
            +
            signing_key: 
         | 
| 43 | 
            +
            specification_version: 4
         | 
| 44 | 
            +
            summary: Rack Middleware implementation of Quotifier by Famingo Labs Inc.
         | 
| 45 | 
            +
            test_files: []
         |