isuggest 0.0.2 → 0.0.3
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/CHANGELOG.md +17 -0
 - data/README.md +13 -0
 - data/init.rb +1 -2
 - data/isuggest.gemspec +1 -1
 - data/lib/isuggest.rb +2 -2
 - data/lib/isuggest/finder.rb +10 -9
 - data/lib/isuggest/version.rb +1 -1
 - metadata +3 -14
 - data/.gitignore +0 -14
 - data/equation.rb +0 -110
 - data/isuggest/.gitignore +0 -14
 - data/isuggest/Gemfile +0 -4
 - data/isuggest/LICENSE.txt +0 -22
 - data/isuggest/README.md +0 -31
 - data/isuggest/Rakefile +0 -2
 - data/isuggest/init.rb +0 -2
 - data/isuggest/isuggest.gemspec +0 -23
 - data/isuggest/lib/isuggest.rb +0 -16
 - data/isuggest/lib/isuggest/finder.rb +0 -46
 - data/isuggest/lib/isuggest/version.rb +0 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d627b9309e261248217e56348d55a35b1ae6bbcf
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 85ebdb80e408d31e6e797f0ba37c39de7bd2a01c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b211697f7980b45e57a0721d7187d650c9f5409c4f3463863a4f0418351cd4c01410e22f9b6024cc0779413fd0418d937494f9b4af60683f949eb6bb81987b49
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a7f8f04bf0c0607be77a887b8ed02a07f16994e6f3458e891b4413d47d6d2dabb9c6cfd5f35f63ec2b22e1d9d2d406584611eca46d0fe625fc2690b05c509a3f
         
     | 
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Isuggest
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            This gem generates a list of suggested name/ email if there already exists a value in the DB. This 
         
     | 
| 
      
 4 
     | 
    
         
            +
            could be user in signup pages when new user creates an account if the email/username is not unique we provide suggesstions
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            ## 0.0.3
         
     | 
| 
      
 8 
     | 
    
         
            +
             - seperator option now  accepts array of characters, default is ['', '_']
         
     | 
| 
      
 9 
     | 
    
         
            +
             - Added CHANGELOG
         
     | 
| 
      
 10 
     | 
    
         
            +
             - updated gemspec files, to fix the gem loading issue 
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## 0.0.2
         
     | 
| 
      
 13 
     | 
    
         
            +
             - Identify email fields and suggest accordingly
         
     | 
| 
      
 14 
     | 
    
         
            +
             - More options like seperator, suggestion count added
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            ## 0.0.1
         
     | 
| 
      
 17 
     | 
    
         
            +
             - First version
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -33,6 +33,19 @@ Options available 
     | 
|
| 
       33 
33 
     | 
    
         
             
            ```
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            Example
         
     | 
| 
      
 39 
     | 
    
         
            +
            ```
         
     | 
| 
      
 40 
     | 
    
         
            +
            class User
         
     | 
| 
      
 41 
     | 
    
         
            +
                suggest_me :on => ['name']
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            new_user = User.new('NewUser')
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            new_user.suggestions # returns arrays of result like ['NewUser1', 'NewUser_2', 'NewUser12', NewUser_1]
         
     | 
| 
      
 47 
     | 
    
         
            +
            ```
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       36 
49 
     | 
    
         
             
            TODO: 
         
     | 
| 
       37 
50 
     | 
    
         
             
            1. Allow users to specify multiple columns in the "on" option
         
     | 
| 
       38 
51 
     | 
    
         | 
    
        data/init.rb
    CHANGED
    
    | 
         @@ -1,2 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'isuggest'
         
     | 
| 
       2 
     | 
    
         
            -
            puts 'Requiring isuggest .................................'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'isuggest'
         
     | 
    
        data/isuggest.gemspec
    CHANGED
    
    | 
         @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       13 
13 
     | 
    
         
             
              spec.homepage      = ""
         
     | 
| 
       14 
14 
     | 
    
         
             
              spec.license       = "MIT"
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              spec.files         = `git ls-files 
     | 
| 
      
 16 
     | 
    
         
            +
              spec.files         = `git ls-files`.split($\)
         
     | 
| 
       17 
17 
     | 
    
         
             
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         
     | 
| 
       18 
18 
     | 
    
         
             
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         
     | 
| 
       19 
19 
     | 
    
         
             
              spec.require_paths = ["lib"]
         
     | 
    
        data/lib/isuggest.rb
    CHANGED
    
    | 
         @@ -7,9 +7,9 @@ module Isuggest 
     | 
|
| 
       7 
7 
     | 
    
         
             
              	raise ArgumentError, "Hash expected, got #{options.class.name}" if !options.empty? && !options.is_a?(Hash) 
         
     | 
| 
       8 
8 
     | 
    
         
             
              	raise ArgumentError, 'No column provides' if options[:on].blank?
         
     | 
| 
       9 
9 
     | 
    
         
             
              	raise ArgumentError, 'No column provides' if options[:on].present? && !options[:on].is_a?(Array)
         
     | 
| 
       10 
     | 
    
         
            -
              	self.isuggest_options = {total_suggestions: 5, seperator: '' }
         
     | 
| 
      
 10 
     | 
    
         
            +
              	self.isuggest_options = {total_suggestions: 5, seperator: ['', '_'] }
         
     | 
| 
       11 
11 
     | 
    
         
             
              	self.isuggest_options.merge!(options)
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
                self.send(:include, Isuggest::Finder)
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
              ActiveRecord::Base.send :extend, Isuggest
         
     | 
    
        data/lib/isuggest/finder.rb
    CHANGED
    
    | 
         @@ -2,16 +2,12 @@ module Isuggest 
     | 
|
| 
       2 
2 
     | 
    
         
             
            	module Finder
         
     | 
| 
       3 
3 
     | 
    
         
             
            		def self.included(base)
         
     | 
| 
       4 
4 
     | 
    
         
             
            			base.extend ClassMethods
         
     | 
| 
       5 
     | 
    
         
            -
            			base.include InstanceMethods
         
     | 
| 
      
 5 
     | 
    
         
            +
            			base.send(:include, InstanceMethods)
         
     | 
| 
       6 
6 
     | 
    
         
             
            		end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            	end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            	module ClassMethods
         
     | 
| 
       11 
     | 
    
         
            -
            		def isuggest_seperator
         
     | 
| 
       12 
     | 
    
         
            -
            			isuggest_options[:seperator]
         
     | 
| 
       13 
     | 
    
         
            -
            		end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
11 
     | 
    
         
             
            		def total_results
         
     | 
| 
       16 
12 
     | 
    
         
             
            			isuggest_options[:total_suggestions].to_i
         
     | 
| 
       17 
13 
     | 
    
         
             
            		end
         
     | 
| 
         @@ -36,7 +32,8 @@ module Isuggest 
     | 
|
| 
       36 
32 
     | 
    
         
             
            		def filter_suggestions(me_suggests, num)
         
     | 
| 
       37 
33 
     | 
    
         
             
            			column_name = isuggest_columns.first
         
     | 
| 
       38 
34 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
            			#Considering totol_results count is relatively small < 500,  
     | 
| 
      
 35 
     | 
    
         
            +
            			#Considering totol_results count is relatively small < 500, 
         
     | 
| 
      
 36 
     | 
    
         
            +
            			#doubling it should reduce the DB hits
         
     | 
| 
       40 
37 
     | 
    
         
             
            			while(me_suggests.length < (self.class.total_results * 2)) do 
         
     | 
| 
       41 
38 
     | 
    
         
             
            			 me_suggests << create_suggestion(self.send(column_name), num) 
         
     | 
| 
       42 
39 
     | 
    
         
             
            			 me_suggests.uniq!
         
     | 
| 
         @@ -50,7 +47,7 @@ module Isuggest 
     | 
|
| 
       50 
47 
     | 
    
         
             
            		end
         
     | 
| 
       51 
48 
     | 
    
         | 
| 
       52 
49 
     | 
    
         
             
            		def isuggest_columns
         
     | 
| 
       53 
     | 
    
         
            -
            			return  
     | 
| 
      
 50 
     | 
    
         
            +
            			return options[:on]
         
     | 
| 
       54 
51 
     | 
    
         
             
            		end
         
     | 
| 
       55 
52 
     | 
    
         | 
| 
       56 
53 
     | 
    
         
             
            		def is_email?
         
     | 
| 
         @@ -58,12 +55,16 @@ module Isuggest 
     | 
|
| 
       58 
55 
     | 
    
         
             
            			self.send(isuggest_columns.first).match(regex).present?
         
     | 
| 
       59 
56 
     | 
    
         
             
            		end
         
     | 
| 
       60 
57 
     | 
    
         | 
| 
      
 58 
     | 
    
         
            +
            		def options
         
     | 
| 
      
 59 
     | 
    
         
            +
            			self.class.isuggest_options
         
     | 
| 
      
 60 
     | 
    
         
            +
            		end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
       61 
62 
     | 
    
         
             
            		def create_suggestion(base_value, num)
         
     | 
| 
       62 
63 
     | 
    
         
             
            			if is_email?
         
     | 
| 
       63 
64 
     | 
    
         
             
            				base_value = base_value.split('@')
         
     | 
| 
       64 
     | 
    
         
            -
            				return "#{base_value.first}#{ 
     | 
| 
      
 65 
     | 
    
         
            +
            				return "#{base_value.first}#{options[:seperator].sample}#{rand(num)}@#{base_value.last}"
         
     | 
| 
       65 
66 
     | 
    
         
             
            			else
         
     | 
| 
       66 
     | 
    
         
            -
            				return "#{base_value}#{ 
     | 
| 
      
 67 
     | 
    
         
            +
            				return "#{base_value}#{options[:seperator].sample}#{rand(num)}"
         
     | 
| 
       67 
68 
     | 
    
         
             
            			end
         
     | 
| 
       68 
69 
     | 
    
         
             
            		end
         
     | 
| 
       69 
70 
     | 
    
         
             
            	end
         
     | 
    
        data/lib/isuggest/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: isuggest
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - roshandevadiga
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-11- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-11-30 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -46,24 +46,13 @@ executables: [] 
     | 
|
| 
       46 
46 
     | 
    
         
             
            extensions: []
         
     | 
| 
       47 
47 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       48 
48 
     | 
    
         
             
            files:
         
     | 
| 
       49 
     | 
    
         
            -
            -  
     | 
| 
      
 49 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       50 
50 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       51 
51 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       52 
52 
     | 
    
         
             
            - README.md
         
     | 
| 
       53 
53 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       54 
     | 
    
         
            -
            - equation.rb
         
     | 
| 
       55 
54 
     | 
    
         
             
            - init.rb
         
     | 
| 
       56 
55 
     | 
    
         
             
            - isuggest.gemspec
         
     | 
| 
       57 
     | 
    
         
            -
            - isuggest/.gitignore
         
     | 
| 
       58 
     | 
    
         
            -
            - isuggest/Gemfile
         
     | 
| 
       59 
     | 
    
         
            -
            - isuggest/LICENSE.txt
         
     | 
| 
       60 
     | 
    
         
            -
            - isuggest/README.md
         
     | 
| 
       61 
     | 
    
         
            -
            - isuggest/Rakefile
         
     | 
| 
       62 
     | 
    
         
            -
            - isuggest/init.rb
         
     | 
| 
       63 
     | 
    
         
            -
            - isuggest/isuggest.gemspec
         
     | 
| 
       64 
     | 
    
         
            -
            - isuggest/lib/isuggest.rb
         
     | 
| 
       65 
     | 
    
         
            -
            - isuggest/lib/isuggest/finder.rb
         
     | 
| 
       66 
     | 
    
         
            -
            - isuggest/lib/isuggest/version.rb
         
     | 
| 
       67 
56 
     | 
    
         
             
            - lib/isuggest.rb
         
     | 
| 
       68 
57 
     | 
    
         
             
            - lib/isuggest/finder.rb
         
     | 
| 
       69 
58 
     | 
    
         
             
            - lib/isuggest/version.rb
         
     | 
    
        data/.gitignore
    DELETED
    
    
    
        data/equation.rb
    DELETED
    
    | 
         @@ -1,110 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Equation consists of characters '+', '-', 'x', '=' and integers. 
         
     | 
| 
       2 
     | 
    
         
            -
            # Characters '+' and '=' never occur at the beginning nor at the end of the equation, the sign '-' is never placed at the end of the 
         
     | 
| 
       3 
     | 
    
         
            -
            # equation, two identical characters can't be put together (pairs '-','+' and '=','+' as well).
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            # Input
         
     | 
| 
       6 
     | 
    
         
            -
            # The first line of the input contains number of tests t (t≤5000). Each test consists of a single line with equation 
         
     | 
| 
       7 
     | 
    
         
            -
            # which doesn't contain any spaces. Length of the equation doesn't exceed 1000 characters.
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            # Output
         
     | 
| 
       10 
     | 
    
         
            -
            # For each test print the solution of the given equation (the solution is always an integer) or NO if the equation doesn't have 
         
     | 
| 
       11 
     | 
    
         
            -
            # exactly one solution.
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            # Input:
         
     | 
| 
       14 
     | 
    
         
            -
            # 2
         
     | 
| 
       15 
     | 
    
         
            -
            # 24-x+3x-2x=16-x
         
     | 
| 
       16 
     | 
    
         
            -
            # 16-4x+2x-12=-2x+10
         
     | 
| 
       17 
     | 
    
         
            -
            # Output:
         
     | 
| 
       18 
     | 
    
         
            -
            # -8
         
     | 
| 
       19 
     | 
    
         
            -
            # NO
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            class InvalidTestSizeError < StandardError; end
         
     | 
| 
       22 
     | 
    
         
            -
            class EquationInvalidError < StandardError; end
         
     | 
| 
       23 
     | 
    
         
            -
            class InvalidInputSize < StandardError; end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            class Equation
         
     | 
| 
       26 
     | 
    
         
            -
            	def initialize(input)
         
     | 
| 
       27 
     | 
    
         
            -
            		@equ =  input
         
     | 
| 
       28 
     | 
    
         
            -
                @solution = nil
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              def validate
         
     | 
| 
       32 
     | 
    
         
            -
                raise InvalidInputSize     if @equ.length > 1000
         
     | 
| 
       33 
     | 
    
         
            -
                raise EquationInvalidError if !syntax_valid?
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
              def solve
         
     | 
| 
       37 
     | 
    
         
            -
                validate
         
     | 
| 
       38 
     | 
    
         
            -
                equ_parts = @equ.split('=')
         
     | 
| 
       39 
     | 
    
         
            -
                lhs = equ_parts.first
         
     | 
| 
       40 
     | 
    
         
            -
                rhs = equ_parts.last
         
     | 
| 
       41 
     | 
    
         
            -
                variable = variable_part(lhs, rhs)
         
     | 
| 
       42 
     | 
    
         
            -
                constant = variable.zero? ? nil : constant_part(rhs, lhs)
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                @solution = constant.fdiv(variable).round(3) if !variable.zero?
         
     | 
| 
       45 
     | 
    
         
            -
                @solution = 0 if !@solution.nil? && @solution.zero? #ignore sign -ve / +ve
         
     | 
| 
       46 
     | 
    
         
            -
              end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
              def display
         
     | 
| 
       49 
     | 
    
         
            -
                puts(@solution.nil? ? 'NO' : @solution)
         
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
              private 
         
     | 
| 
       53 
     | 
    
         
            -
              def syntax_valid?
         
     | 
| 
       54 
     | 
    
         
            -
                return (first_char_valid? && last_char_valid? && signs_valid?)
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              def first_char_valid?
         
     | 
| 
       58 
     | 
    
         
            -
                !['+', '='].include?(@equ[0])
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              def last_char_valid?
         
     | 
| 
       62 
     | 
    
         
            -
                !['-','+', '='].include?(@equ[@equ.length - 1])
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              def signs_valid?
         
     | 
| 
       66 
     | 
    
         
            -
                @equ.scan(/(xx|\s|--|\+\+|==|\+=)/).length == 0
         
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
              def constant_part(rhs, lhs)
         
     | 
| 
       70 
     | 
    
         
            -
                regex = /(\+[0-9]+|-[0-9]+|[0-9]+)/
         
     | 
| 
       71 
     | 
    
         
            -
                variable_regex = /(\+[0-9]+|-[0-9]+|[0-9]+)x/
         
     | 
| 
       72 
     | 
    
         
            -
                lhs_part = lhs.scan(regex).flatten.uniq - lhs.scan(variable_regex).flatten.uniq 
         
     | 
| 
       73 
     | 
    
         
            -
                rhs_part = rhs.scan(regex).flatten.uniq - rhs.scan(variable_regex).flatten.uniq 
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                return (sum(rhs_part) - sum(lhs_part))
         
     | 
| 
       76 
     | 
    
         
            -
              end
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
              def variable_part(lhs, rhs)
         
     | 
| 
       79 
     | 
    
         
            -
                regex = /([0-9]*|\+[0-9]*|-[0-9]*)x/
         
     | 
| 
       80 
     | 
    
         
            -
                lhs_part = lhs.scan(regex).flatten.map{|item| item.empty? ? '1' : item}
         
     | 
| 
       81 
     | 
    
         
            -
                rhs_part = rhs.scan(regex).flatten.map{|item| item.empty? ? '1' : item}
         
     | 
| 
       82 
     | 
    
         
            -
                
         
     | 
| 
       83 
     | 
    
         
            -
                return ( sum(lhs_part) - sum(rhs_part) )
         
     | 
| 
       84 
     | 
    
         
            -
              end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
              def sum(val)
         
     | 
| 
       87 
     | 
    
         
            -
                return val.collect(&:to_i).inject(&:+) || 0
         
     | 
| 
       88 
     | 
    
         
            -
              end
         
     | 
| 
       89 
     | 
    
         
            -
            end
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
            begin
         
     | 
| 
       92 
     | 
    
         
            -
              no_of_test = gets.chomp.to_i
         
     | 
| 
       93 
     | 
    
         
            -
              raise InvalidTestSizeError if no_of_test > 5000
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
              equations = []
         
     | 
| 
       96 
     | 
    
         
            -
              no_of_test.times do
         
     | 
| 
       97 
     | 
    
         
            -
                equations << Equation.new(gets.chomp)
         
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
              for itr in 0..(no_of_test - 1) do
         
     | 
| 
       101 
     | 
    
         
            -
                equations[itr].solve
         
     | 
| 
       102 
     | 
    
         
            -
                equations[itr].display
         
     | 
| 
       103 
     | 
    
         
            -
              end  
         
     | 
| 
       104 
     | 
    
         
            -
            rescue InvalidInputSize => e
         
     | 
| 
       105 
     | 
    
         
            -
              puts 'Input size should be less than 5000 characters'
         
     | 
| 
       106 
     | 
    
         
            -
            rescue EquationInvalidError => e
         
     | 
| 
       107 
     | 
    
         
            -
              puts 'Equation is not valid, please check the defined rules'
         
     | 
| 
       108 
     | 
    
         
            -
            rescue InvalidTestSizeError => e
         
     | 
| 
       109 
     | 
    
         
            -
              puts 'Number of tests should be less than 1000'
         
     | 
| 
       110 
     | 
    
         
            -
            end
         
     | 
    
        data/isuggest/.gitignore
    DELETED
    
    
    
        data/isuggest/Gemfile
    DELETED
    
    
    
        data/isuggest/LICENSE.txt
    DELETED
    
    | 
         @@ -1,22 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Copyright (c) 2014 roshandevadiga
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            MIT License
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
       6 
     | 
    
         
            -
            a copy of this software and associated documentation files (the
         
     | 
| 
       7 
     | 
    
         
            -
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
       8 
     | 
    
         
            -
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
       9 
     | 
    
         
            -
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
       10 
     | 
    
         
            -
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
       11 
     | 
    
         
            -
            the following conditions:
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            The above copyright notice and this permission notice shall be
         
     | 
| 
       14 
     | 
    
         
            -
            included in all copies or substantial portions of the Software.
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
       17 
     | 
    
         
            -
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
       18 
     | 
    
         
            -
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
       19 
     | 
    
         
            -
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
       20 
     | 
    
         
            -
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
       21 
     | 
    
         
            -
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
       22 
     | 
    
         
            -
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/isuggest/README.md
    DELETED
    
    | 
         @@ -1,31 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Isuggest
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            TODO: Write a gem description
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            ## Installation
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            Add this line to your application's Gemfile:
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       10 
     | 
    
         
            -
            gem 'isuggest'
         
     | 
| 
       11 
     | 
    
         
            -
            ```
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            And then execute:
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                $ bundle
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            Or install it yourself as:
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                $ gem install isuggest
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            ## Usage
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
            TODO: Write usage instructions here
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            ## Contributing
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
            1. Fork it ( https://github.com/[my-github-username]/isuggest/fork )
         
     | 
| 
       28 
     | 
    
         
            -
            2. Create your feature branch (`git checkout -b my-new-feature`)
         
     | 
| 
       29 
     | 
    
         
            -
            3. Commit your changes (`git commit -am 'Add some feature'`)
         
     | 
| 
       30 
     | 
    
         
            -
            4. Push to the branch (`git push origin my-new-feature`)
         
     | 
| 
       31 
     | 
    
         
            -
            5. Create a new Pull Request
         
     | 
    
        data/isuggest/Rakefile
    DELETED
    
    
    
        data/isuggest/init.rb
    DELETED
    
    
    
        data/isuggest/isuggest.gemspec
    DELETED
    
    | 
         @@ -1,23 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # coding: utf-8
         
     | 
| 
       2 
     | 
    
         
            -
            lib = File.expand_path('../lib', __FILE__)
         
     | 
| 
       3 
     | 
    
         
            -
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
       4 
     | 
    
         
            -
            require 'isuggest/version'
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            Gem::Specification.new do |spec|
         
     | 
| 
       7 
     | 
    
         
            -
              spec.name          = "isuggest"
         
     | 
| 
       8 
     | 
    
         
            -
              spec.version       = Isuggest::VERSION
         
     | 
| 
       9 
     | 
    
         
            -
              spec.authors       = ["roshandevadiga"]
         
     | 
| 
       10 
     | 
    
         
            -
              spec.email         = ["roshan.devadiga@gmail.com"]
         
     | 
| 
       11 
     | 
    
         
            -
              spec.summary       = %q{This gem will give suggestions for the fields that should be unique.}
         
     | 
| 
       12 
     | 
    
         
            -
              spec.description   = %q{Include this in your model and pass the column name that should be unique. Based on the column if the column is already present the gem will provide you suggesstions}
         
     | 
| 
       13 
     | 
    
         
            -
              spec.homepage      = ""
         
     | 
| 
       14 
     | 
    
         
            -
              spec.license       = "MIT"
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              spec.files         = `git ls-files -z`.split("\x0")
         
     | 
| 
       17 
     | 
    
         
            -
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         
     | 
| 
       18 
     | 
    
         
            -
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         
     | 
| 
       19 
     | 
    
         
            -
              spec.require_paths = ["lib"]
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              spec.add_development_dependency "bundler", "~> 1.7"
         
     | 
| 
       22 
     | 
    
         
            -
              spec.add_development_dependency "rake", "~> 10.0"
         
     | 
| 
       23 
     | 
    
         
            -
            end
         
     | 
    
        data/isuggest/lib/isuggest.rb
    DELETED
    
    | 
         @@ -1,16 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "isuggest/version"
         
     | 
| 
       2 
     | 
    
         
            -
            require "isuggest/finder"
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            module Isuggest
         
     | 
| 
       5 
     | 
    
         
            -
               def suggest_me(options={})
         
     | 
| 
       6 
     | 
    
         
            -
               	class_attribute :isuggest_options
         
     | 
| 
       7 
     | 
    
         
            -
              	raise ArgumentError, "Hash expected, got #{options.class.name}" if !options.empty? && !options.is_a?(Hash) 
         
     | 
| 
       8 
     | 
    
         
            -
              	raise ArgumentError, 'No column provides' if options[:on].blank?
         
     | 
| 
       9 
     | 
    
         
            -
              	raise ArgumentError, 'No column provides' if options[:on].present? && !options[:on].is_a?(Array)
         
     | 
| 
       10 
     | 
    
         
            -
              	self.isuggest_options = {total_suggestions: 5, seperator: '' }
         
     | 
| 
       11 
     | 
    
         
            -
              	self.isuggest_options.merge!(options)
         
     | 
| 
       12 
     | 
    
         
            -
              	include Isuggest::Finder
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
            	  	
         
     | 
| 
       15 
     | 
    
         
            -
              ActiveRecord::Base.send :extend, Isuggest
         
     | 
| 
       16 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,46 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Isuggest
         
     | 
| 
       2 
     | 
    
         
            -
            	module Finder
         
     | 
| 
       3 
     | 
    
         
            -
            		def self.included(base)
         
     | 
| 
       4 
     | 
    
         
            -
            			base.extend ClassMethods
         
     | 
| 
       5 
     | 
    
         
            -
            			base.include InstanceMethods
         
     | 
| 
       6 
     | 
    
         
            -
            		end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            	end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            	module ClassMethods
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
            	end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            	module InstanceMethods
         
     | 
| 
       15 
     | 
    
         
            -
            		def is_unique?
         
     | 
| 
       16 
     | 
    
         
            -
            			column_name = isuggest_columns.first.to_sym
         
     | 
| 
       17 
     | 
    
         
            -
            			return !self.class.exists?(column_name => self.send(column_name))
         
     | 
| 
       18 
     | 
    
         
            -
            		end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            		def suggestions
         
     | 
| 
       21 
     | 
    
         
            -
            			me_suggests = []
         
     | 
| 
       22 
     | 
    
         
            -
            			number = 10
         
     | 
| 
       23 
     | 
    
         
            -
            			while me_suggests.length < self.class.isuggest_options[:total_suggestions].to_i
         
     | 
| 
       24 
     | 
    
         
            -
            				me_suggests = filter_suggestions(me_suggests, number)
         
     | 
| 
       25 
     | 
    
         
            -
            				number = number * 10
         
     | 
| 
       26 
     | 
    
         
            -
            			end
         
     | 
| 
       27 
     | 
    
         
            -
            			return me_suggests
         
     | 
| 
       28 
     | 
    
         
            -
            		end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
            		def filter_suggestions(me_suggests, number)
         
     | 
| 
       31 
     | 
    
         
            -
            			column_name = isuggest_columns.first
         
     | 
| 
       32 
     | 
    
         
            -
            			base_value = self.send(column_name)
         
     | 
| 
       33 
     | 
    
         
            -
            			while(me_suggests.length < 6) do
         
     | 
| 
       34 
     | 
    
         
            -
            				 me_suggests << "#{base_value}#{self.class.isuggest_options[:seperator]}#{rand(number)}"
         
     | 
| 
       35 
     | 
    
         
            -
            				 me_suggests.uniq!
         
     | 
| 
       36 
     | 
    
         
            -
            			end
         
     | 
| 
       37 
     | 
    
         
            -
            			results = self.class.where(["#{column_name} in (#{me_suggests.map{|s| '"'+s+'"'}.join(',')})"]).select(column_name).collect(&:"#{column_name}")
         
     | 
| 
       38 
     | 
    
         
            -
            			
         
     | 
| 
       39 
     | 
    
         
            -
            			return (results.length == 0) ? me_suggests : (me_suggests - results)
         
     | 
| 
       40 
     | 
    
         
            -
            		end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
            		def isuggest_columns
         
     | 
| 
       43 
     | 
    
         
            -
            			return self.class.isuggest_options[:on]
         
     | 
| 
       44 
     | 
    
         
            -
            		end
         
     | 
| 
       45 
     | 
    
         
            -
            	end
         
     | 
| 
       46 
     | 
    
         
            -
            end
         
     |