searchmatcher 0.0.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 +7 -0
 - data/lib/searchmatcher.rb +34 -0
 - metadata +44 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1d506fb34c82a76280f9d54da82ff0da7c63b4f0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2151a5cc305e32c27e54e6121336266de9749f87
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e9344f747299ec5c0135cb68385d8bdec9acc343b1672a735dbd7c4d65b20acb59a5ac42930bf6bb2c2c51fc131d38134f94be0e462975ac514ce77983a6524b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ee437a9804fa2cf318e695794b3ccc48677b99bc95a04792eda84da0b8bd071a75930657c843c03d4ad696b0783b74e9d1142b00d1270953c4e17696cdaee256
         
     | 
| 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Searchmatcher
         
     | 
| 
      
 2 
     | 
    
         
            +
              def initialize(klass, options)
         
     | 
| 
      
 3 
     | 
    
         
            +
                @field = options.keys.first.to_s
         
     | 
| 
      
 4 
     | 
    
         
            +
                @value = options.values.first
         
     | 
| 
      
 5 
     | 
    
         
            +
                @klass = klass
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              def results
         
     | 
| 
      
 9 
     | 
    
         
            +
                 klass.where(formater, search: "#{value}%")
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              def formater
         
     | 
| 
      
 13 
     | 
    
         
            +
                return {} if field.nil? || field.blank?
         
     | 
| 
      
 14 
     | 
    
         
            +
                field.split("_or_").map { |f| f  + " LIKE :search" }.join(" OR ")
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              attr_accessor :field, :value, :klass
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            #should pass the className and fields with value as hash
         
     | 
| 
      
 21 
     | 
    
         
            +
            # example 1
         
     | 
| 
      
 22 
     | 
    
         
            +
            # @jobs = Searchmatcher.new(Job, {name: "software"}).results
         
     | 
| 
      
 23 
     | 
    
         
            +
            # example 2
         
     | 
| 
      
 24 
     | 
    
         
            +
            # @jobs = Searchmatcher.new(Job, {title_or_description: "software"}).results
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            # form can be a controller add specific page controller or actions inside the form_tag
         
     | 
| 
      
 27 
     | 
    
         
            +
            #<%= form_tag("/jobs", method: "get") do %>
         
     | 
| 
      
 28 
     | 
    
         
            +
            # <%= label_tag(:title_or_description, "Search for:") %>
         
     | 
| 
      
 29 
     | 
    
         
            +
            # <%= text_field_tag "search[title_or_description]" %>
         
     | 
| 
      
 30 
     | 
    
         
            +
            # <%= submit_tag("Search") %>
         
     | 
| 
      
 31 
     | 
    
         
            +
            #<% end %>
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            #get the params
         
     | 
| 
      
 34 
     | 
    
         
            +
            # @jobs = Searchmatcher.new(Job, params["search"]).results
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: searchmatcher
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Karthik
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-11-29 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: A search gem
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: karthikeyagayaru9@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 16 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            files:
         
     | 
| 
      
 19 
     | 
    
         
            +
            - lib/searchmatcher.rb
         
     | 
| 
      
 20 
     | 
    
         
            +
            homepage: http://rubygems.org/gems/searchmatcher
         
     | 
| 
      
 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.5.1
         
     | 
| 
      
 41 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 42 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 43 
     | 
    
         
            +
            summary: Search
         
     | 
| 
      
 44 
     | 
    
         
            +
            test_files: []
         
     |