parenthesize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Anil Sharma
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,65 @@
1
+ = parenthesize
2
+
3
+ Parenthesize parameters in string or array to use in a SQL IN statement.
4
+
5
+ == Install
6
+
7
+ Install parenthesize like any other ruby gem:
8
+
9
+ gem install parenthesize
10
+
11
+ == Overview of usage
12
+
13
+ parenthesize puts a single element or a group of elements inside paranthesis
14
+ in a format expected by the SQL statements IN clause.
15
+
16
+ == Commands
17
+
18
+ Available Command:
19
+
20
+ str = "ABC"
21
+ str.paranthesize # ('ABC')
22
+
23
+ arr = ["ABC", "DEF", "XYZ"]
24
+ arr.paranthesize # ('ABC', 'DEF', 'XYZ')
25
+
26
+ num = 789
27
+ num.paranthesize # (789)
28
+
29
+ arr_num = [123, 456, 789]
30
+ arr_num.paranthesize # (123, 456, 789)
31
+
32
+ == Where to use parenthesize
33
+
34
+ You can build a SQL query as follows:
35
+
36
+ "SELECT id, name, address, fld from users where fld in #{my_flds.parenthesize} order by id"
37
+
38
+ Now my_ids will support the following values:
39
+
40
+ my_flds = 789 # (789)
41
+ my_flds = [123, 456, 789] # (123, 456, 789)
42
+ my_flds = 'ABC' # ('ABC')
43
+ my_flds = ['ABC', 'DEF', 'XYZ'] # ('ABC', 'DEF', 'XYZ')
44
+
45
+ == Issues, Suggestions
46
+
47
+ * https://github.com/aksharma/parenthesize/issues/
48
+ * or email me directly at (sharma.rubyonrails)
49
+ * this address ( @ )
50
+ * (sharmail_dot_com )
51
+
52
+ == Contributing to parenthesize
53
+
54
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
55
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
56
+ * Fork the project.
57
+ * Start a feature/bugfix branch.
58
+ * Commit and push until you are happy with your contribution.
59
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
60
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
61
+
62
+ == Copyright
63
+
64
+ Copyright (c) 2012 Anil Sharma. See LICENSE for further details.
65
+
@@ -0,0 +1,19 @@
1
+ class String
2
+ def parenthesize
3
+ "('" + self + "')"
4
+ end
5
+ end
6
+
7
+ class Numeric
8
+ def parenthesize
9
+ "(" + self.to_s + ")"
10
+ end
11
+ end
12
+
13
+ class Array
14
+ def parenthesize
15
+ '(' +
16
+ self.map{|item| (item.is_a? String) ? ("'" + item + "'") : item}.join(',') +
17
+ ')'
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Parenthesize String" do
4
+ it "should put quotes around the string and parenthesize()" do
5
+ f = %q(test string)
6
+ f.parenthesize.should == "('test string')"
7
+ end
8
+ end
9
+
10
+ describe "Parenthesize Numeric integer" do
11
+ it "should parenthesize integer" do
12
+ f = 99
13
+ f.parenthesize.should == "(99)"
14
+ end
15
+ end
16
+
17
+ describe "Parenthesize Numeric float" do
18
+ it "should parenthesize float" do
19
+ f = 9.9
20
+ f.parenthesize.should == "(9.9)"
21
+ end
22
+ end
23
+
24
+ describe "Parenthesize Numeric negative float" do
25
+ it "should parenthesize float" do
26
+ f = -9.9
27
+ f.parenthesize.should == "(-9.9)"
28
+ end
29
+ end
30
+
31
+ describe "Parenthesize Array" do
32
+ it "should put quotes around the string elements and parenthesize()" do
33
+ f = [9, "b"]
34
+ f.parenthesize.should == "(9,'b')"
35
+ end
36
+ end
37
+
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'parenthesize'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parenthesize
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Anil Sharma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-06-07 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Extends the String and Array classes to use in a SQL IN statement.
18
+ email: sharma.ruby2gem@sharmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/parenthesize.rb
27
+ - spec/spec_helper.rb
28
+ - spec/parenthesize_spec.rb
29
+ - README.rdoc
30
+ - LICENSE
31
+ - spec//spec_helper.rb
32
+ has_rdoc: true
33
+ homepage: http://rubygems.org/gems/parenthesize
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.5.3
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Parenthesize parameters in string or array to use in a SQL IN statement.
60
+ test_files:
61
+ - spec//spec_helper.rb
62
+ - spec/parenthesize_spec.rb