quote_unquote 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -0
- data/lib/quote_unquote/string_ext.rb +8 -8
- data/lib/quote_unquote/version.rb +1 -1
- data/test/test_quote_unquote.rb +13 -0
- metadata +3 -2
data/README.markdown
CHANGED
@@ -19,6 +19,17 @@ require 'quote_unquote'
|
|
19
19
|
'"hello"'.uqq # hello
|
20
20
|
```
|
21
21
|
|
22
|
+
"Is this a joke?"
|
23
|
+
"Yup."
|
24
|
+
|
25
|
+
## Slightly, just slightly more useful examples
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Escapes the quotation marks
|
29
|
+
"I'm good".q("''") # 'I''m good'
|
30
|
+
"I'm good".q("''").uq("''") # I'm good
|
31
|
+
```
|
32
|
+
|
22
33
|
## Copyright
|
23
34
|
|
24
35
|
Copyright (c) 2011 Junegunn Choi. See LICENSE.txt for
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module QuoteUnquote
|
2
2
|
module StringExtension
|
3
3
|
# Wraps the String with single quotes
|
4
|
-
def q
|
5
|
-
%['#{self}']
|
4
|
+
def q esc = nil
|
5
|
+
%['#{esc ? self.gsub("'") { esc } : self}']
|
6
6
|
end
|
7
7
|
|
8
8
|
# Wraps the String with double quotes
|
9
|
-
def qq
|
10
|
-
%["#{self}"]
|
9
|
+
def qq esc = nil
|
10
|
+
%["#{esc ? self.gsub('"') { esc } : self}"]
|
11
11
|
end
|
12
12
|
|
13
13
|
# Unwraps single quotes
|
14
|
-
def uq
|
15
|
-
self.gsub(/\A'|'\Z/, '')
|
14
|
+
def uq esc = nil
|
15
|
+
(esc ? self.gsub(esc, "'") : self).gsub(/\A'|'\Z/, '')
|
16
16
|
end
|
17
17
|
|
18
18
|
# Unwraps double quotes
|
19
|
-
def uqq
|
20
|
-
self.gsub(/\A"|"\Z/, '')
|
19
|
+
def uqq esc = nil
|
20
|
+
(esc ? self.gsub(esc, '"') : self).gsub(/\A"|"\Z/, '')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/test/test_quote_unquote.rb
CHANGED
@@ -23,4 +23,17 @@ class TestQuoteUnquote < Test::Unit::TestCase
|
|
23
23
|
assert_equal %[hello], '"hello"'.uqq
|
24
24
|
assert_equal %[hello"\n"world], "\"hello\"\n\"world\"".uqq
|
25
25
|
end
|
26
|
+
|
27
|
+
def test_q_esc
|
28
|
+
assert_equal %['I''m good'], "I'm good".q("''")
|
29
|
+
assert_equal %[I'm good], "I'm good".q("''").uq("''")
|
30
|
+
|
31
|
+
assert_equal %['I\\'m good'], "I'm good".q("\\'")
|
32
|
+
assert_equal %[I'm good], "I'm good".q("\\'").uq("\\'")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_qq_esc
|
36
|
+
assert_equal %["Say \\"Ho\\""], 'Say "Ho"'.qq("\\\"")
|
37
|
+
assert_equal %[Say "Ho"], 'Say "Ho"'.qq("\\\"").uqq('\"')
|
38
|
+
end
|
26
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quote_unquote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Wraps and unwraps strings with quotes
|
15
15
|
email:
|
@@ -54,3 +54,4 @@ specification_version: 3
|
|
54
54
|
summary: Wraps and unwraps strings with quotes
|
55
55
|
test_files:
|
56
56
|
- test/test_quote_unquote.rb
|
57
|
+
has_rdoc:
|