strings-case 0.2.0 → 0.4.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 +4 -4
- data/CHANGELOG.md +27 -1
- data/LICENSE.txt +1 -1
- data/README.md +231 -131
- data/lib/strings/case/acronyms.rb +111 -0
- data/lib/strings/case/configuration.rb +55 -0
- data/lib/strings/case/extensions.rb +56 -6
- data/lib/strings/case/version.rb +4 -4
- data/lib/strings/case.rb +248 -145
- metadata +17 -40
- data/Rakefile +0 -8
- data/spec/spec_helper.rb +0 -39
- data/spec/unit/camelcase_spec.rb +0 -51
- data/spec/unit/constcase_spec.rb +0 -44
- data/spec/unit/extensions_spec.rb +0 -75
- data/spec/unit/headercase_spec.rb +0 -50
- data/spec/unit/kebabcase_spec.rb +0 -48
- data/spec/unit/pascalcase_spec.rb +0 -51
- data/spec/unit/pathcase_spec.rb +0 -51
- data/spec/unit/sentencecase_spec.rb +0 -51
- data/spec/unit/snakecase_spec.rb +0 -51
- data/spec/unit/titlecase_spec.rb +0 -51
- data/strings-case.gemspec +0 -32
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
data/spec/spec_helper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if ENV["COVERAGE"] || ENV["TRAVIS"]
|
4
|
-
require "simplecov"
|
5
|
-
require "coveralls"
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
])
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name "spec"
|
14
|
-
add_filter "spec"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require "bundler/setup"
|
19
|
-
require "strings/case"
|
20
|
-
|
21
|
-
module Helpers
|
22
|
-
def modern_ruby?
|
23
|
-
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
RSpec.configure do |config|
|
28
|
-
config.extend Helpers
|
29
|
-
|
30
|
-
# Enable flags like --only-failures and --next-failure
|
31
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
32
|
-
|
33
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
34
|
-
config.disable_monkey_patching!
|
35
|
-
|
36
|
-
config.expect_with :rspec do |c|
|
37
|
-
c.syntax = :expect
|
38
|
-
end
|
39
|
-
end
|
data/spec/unit/camelcase_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#camelcase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"f" => "f",
|
8
|
-
"1234" => "1234",
|
9
|
-
"FOO" => "foo",
|
10
|
-
"FooBar" => "fooBar",
|
11
|
-
"fooBar" => "fooBar",
|
12
|
-
"foo bar" => "fooBar",
|
13
|
-
"Foo - Bar" => "fooBar",
|
14
|
-
"foo & bar" => "fooBar",
|
15
|
-
"FooFooBar" => "fooFooBar",
|
16
|
-
"Foo2Foo2Bar" => "foo2Foo2Bar",
|
17
|
-
"foo-bar-baz" => "fooBarBaz",
|
18
|
-
"foo_bar_1_2" => "fooBar12",
|
19
|
-
"_foo_bar_baz_" => "fooBarBaz",
|
20
|
-
"--foo-bar--" => "fooBar",
|
21
|
-
"FOO_BAR_baz" => "fooBarBaz",
|
22
|
-
"__FOO_BAR__" => "fooBar",
|
23
|
-
"Foo w1th apo's and punc]t" => "fooW1thAposAndPunct",
|
24
|
-
"getHTTPResponse" => "getHttpResponse",
|
25
|
-
"currencyISOCode" => "currencyIsoCode",
|
26
|
-
"get2HTTPResponse" => "get2HttpResponse",
|
27
|
-
"HTTPResponseCode" => "httpResponseCode",
|
28
|
-
"HTTPResponseCodeXY" => "httpResponseCodeXy",
|
29
|
-
"supports IPv6 on iOS?" => "supportsIpv6OnIos"
|
30
|
-
}.each do |actual, expected|
|
31
|
-
it "applies camelcase to #{actual.inspect} -> #{expected.inspect}" do
|
32
|
-
expect(Strings::Case.camelcase(actual)).to eq(expected)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "supports unicode", if: modern_ruby? do
|
37
|
-
expect(Strings::Case.camelcase("ЗдравствуйтеПривет")).to eq("здравствуйтеПривет")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to preserve acronyms" do
|
41
|
-
camelized = Strings::Case.lower_camelcase("HTTP response code", acronyms: ["HTTP"])
|
42
|
-
|
43
|
-
expect(camelized).to eq("HTTPResponseCode")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "changes a separator to :" do
|
47
|
-
camelized = Strings::Case.camelcase("HTTP response code", separator: ":")
|
48
|
-
|
49
|
-
expect(camelized).to eq("http:Response:Code")
|
50
|
-
end
|
51
|
-
end
|
data/spec/unit/constcase_spec.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#constcase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"1234" => "1234",
|
8
|
-
"FOO" => "FOO",
|
9
|
-
"FooBar" => "FOO_BAR",
|
10
|
-
"fooBar" => "FOO_BAR",
|
11
|
-
"foo bar" => "FOO_BAR",
|
12
|
-
"Foo - Bar" => "FOO_BAR",
|
13
|
-
"foo & bar" => "FOO_BAR",
|
14
|
-
"FooFooBar" => "FOO_FOO_BAR",
|
15
|
-
"Foo2Foo2Bar" => "FOO2_FOO2_BAR",
|
16
|
-
"foo-bar-baz" => "FOO_BAR_BAZ",
|
17
|
-
"foo_bar_1_2" => "FOO_BAR_1_2",
|
18
|
-
"_foo_bar_baz_" => "_FOO_BAR_BAZ_",
|
19
|
-
"--foo-bar--" => "FOO_BAR",
|
20
|
-
"FOO_BAR_baz" => "FOO_BAR_BAZ",
|
21
|
-
"__FOO_BAR__" => "_FOO_BAR_",
|
22
|
-
"Foo w1th apo's and punc]t" => "FOO_W1TH_APOS_AND_PUNCT",
|
23
|
-
"getHTTPResponse" => "GET_HTTP_RESPONSE",
|
24
|
-
"currencyISOCode" => "CURRENCY_ISO_CODE",
|
25
|
-
"get2HTTPResponse" => "GET2_HTTP_RESPONSE",
|
26
|
-
"HTTPResponseCode" => "HTTP_RESPONSE_CODE",
|
27
|
-
"HTTPResponseCodeXY" => "HTTP_RESPONSE_CODE_XY",
|
28
|
-
"supports IPv6 on iOS?" => "SUPPORTS_IPV6_ON_IOS",
|
29
|
-
}.each do |actual, expected|
|
30
|
-
it "applies constcase to #{actual.inspect} -> #{expected.inspect}" do
|
31
|
-
expect(Strings::Case.constcase(actual)).to eq(expected)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "supports unicode", if: modern_ruby? do
|
36
|
-
expect(Strings::Case.constantcase("ЗдравствуйтеПривет")).to eq("ЗДРАВСТВУЙТЕ_ПРИВЕТ")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "changes a separator to :" do
|
40
|
-
constant = Strings::Case.constcase("HTTP response code", separator: ":")
|
41
|
-
|
42
|
-
expect(constant).to eq("HTTP:RESPONSE:CODE")
|
43
|
-
end
|
44
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "strings/case/extensions"
|
4
|
-
|
5
|
-
using Strings::Case::Extensions
|
6
|
-
|
7
|
-
RSpec.describe Strings::Case::Extensions do
|
8
|
-
it "camelcase a string" do
|
9
|
-
expect("foo bar baz".camelcase).to eq("fooBarBaz")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "camelcase a string with acronyms" do
|
13
|
-
expect("HTTP Response Code".lower_camelcase(acronyms: ["HTTP"])).to eq("HTTPResponseCode")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "constcase a string" do
|
17
|
-
expect("foo bar baz".constcase).to eq("FOO_BAR_BAZ")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "headercases a string" do
|
21
|
-
expect("foo bar baz".headercase).to eq("Foo-Bar-Baz")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "headercases a string with acronyms" do
|
25
|
-
expect("HTTP Response Code".headercase(acronyms: ["HTTP"])).to eq("HTTP-Response-Code")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "kebabcases a string" do
|
29
|
-
expect("foo bar baz".kebabcase).to eq("foo-bar-baz")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "kebabcases a string with acronyms" do
|
33
|
-
expect("HTTP Response Code".dashcase(acronyms: ["HTTP"])).to eq("HTTP-response-code")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "pascalcases a string" do
|
37
|
-
expect("foo bar baz".pascalcase).to eq("FooBarBaz")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "pascalcases a string with acronyms" do
|
41
|
-
expect("HTTP Response Code".pascalcase(acronyms: ["HTTP"])).to eq("HTTPResponseCode")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "pathcases a string" do
|
45
|
-
expect("foo bar baz".pathcase).to eq("foo/bar/baz")
|
46
|
-
end
|
47
|
-
|
48
|
-
it "pathcases a string with acronyms" do
|
49
|
-
expect("HTTP Response Code".pathcase(acronyms: ["HTTP"])).to eq("HTTP/response/code")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "sentencecases a string" do
|
53
|
-
expect("foo bar baz".sentencecase).to eq("Foo bar baz")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "sentencecases a string with acronyms" do
|
57
|
-
expect("HTTP Response Code".sentencecase(acronyms: ["HTTP"])).to eq("HTTP response code")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "snakecases a string" do
|
61
|
-
expect("foo bar baz".snakecase).to eq("foo_bar_baz")
|
62
|
-
end
|
63
|
-
|
64
|
-
it "snakecases a string with acronyms" do
|
65
|
-
expect("HTTP Response Code".underscore(acronyms: ["HTTP"])).to eq("HTTP_response_code")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "titlecases a string" do
|
69
|
-
expect("foo bar baz".titlecase).to eq("Foo Bar Baz")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "titlecase a string with acronyms" do
|
73
|
-
expect("HTTP Response Code".titlecase(acronyms: ["HTTP"])).to eq("HTTP Response Code")
|
74
|
-
end
|
75
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#headercase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"1234" => "1234",
|
8
|
-
"FOO" => "Foo",
|
9
|
-
"FooBar" => "Foo-Bar",
|
10
|
-
"fooBar" => "Foo-Bar",
|
11
|
-
"foo bar" => "Foo-Bar",
|
12
|
-
"Foo - Bar" => "Foo-Bar",
|
13
|
-
"foo & bar" => "Foo-Bar",
|
14
|
-
"FooFooBar" => "Foo-Foo-Bar",
|
15
|
-
"Foo2Foo2Bar" => "Foo2-Foo2-Bar",
|
16
|
-
"foo-bar-baz" => "Foo-Bar-Baz",
|
17
|
-
"foo_bar_1_2" => "Foo-Bar-1-2",
|
18
|
-
"_foo_bar_baz_" => "Foo-Bar-Baz",
|
19
|
-
"--foo-bar--" => "-Foo-Bar-",
|
20
|
-
"FOO_BAR_baz" => "Foo-Bar-Baz",
|
21
|
-
"__FOO_BAR__" => "Foo-Bar",
|
22
|
-
"Foo w1th apo's and punc]t" => "Foo-W1th-Apos-And-Punct",
|
23
|
-
"getHTTPResponse" => "Get-Http-Response",
|
24
|
-
"currencyISOCode" => "Currency-Iso-Code",
|
25
|
-
"get2HTTPResponse" => "Get2-Http-Response",
|
26
|
-
"HTTPResponseCode" => "Http-Response-Code",
|
27
|
-
"HTTPResponseCodeXY" => "Http-Response-Code-Xy",
|
28
|
-
"supports IPv6 on iOS?" => "Supports-Ipv6-On-Ios",
|
29
|
-
}.each do |actual, expected|
|
30
|
-
it "applies headercase to #{actual.inspect} -> #{expected.inspect}" do
|
31
|
-
expect(Strings::Case.headercase(actual)).to eq(expected)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "supports unicode", if: modern_ruby? do
|
36
|
-
expect(Strings::Case.headercase("ЗдравствуйтеПривет")).to eq("Здравствуйте-Привет")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "allows to preserve acronyms" do
|
40
|
-
headered = Strings::Case.headercase("HTTP response code", acronyms: ["HTTP"])
|
41
|
-
|
42
|
-
expect(headered).to eq("HTTP-Response-Code")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "changes a separator to :" do
|
46
|
-
headered = Strings::Case.headercase("HTTP response code", separator: ":")
|
47
|
-
|
48
|
-
expect(headered).to eq("Http:Response:Code")
|
49
|
-
end
|
50
|
-
end
|
data/spec/unit/kebabcase_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#kebabcase" do
|
4
|
-
{
|
5
|
-
"" => "",
|
6
|
-
"1234" => "1234",
|
7
|
-
"FOO" => "foo",
|
8
|
-
"FooBar" => "foo-bar",
|
9
|
-
"fooBar" => "foo-bar",
|
10
|
-
"foo bar" => "foo-bar",
|
11
|
-
"Foo - Bar" => "foo-bar",
|
12
|
-
"foo & bar" => "foo-bar",
|
13
|
-
"FooFooBar" => "foo-foo-bar",
|
14
|
-
"Foo2Foo2Bar" => "foo2-foo2-bar",
|
15
|
-
"foo-bar-baz" => "foo-bar-baz",
|
16
|
-
"_foo_bar_baz_" => "foo-bar-baz",
|
17
|
-
"--foo-bar--" => "-foo-bar-",
|
18
|
-
"FOO_BAR_baz" => "foo-bar-baz",
|
19
|
-
"__FOO_BAR__" => "foo-bar",
|
20
|
-
"Foo w1th apo's and punc]t" => "foo-w1th-apos-and-punct",
|
21
|
-
"getHTTPResponse" => "get-http-response",
|
22
|
-
"currencyISOCode" => "currency-iso-code",
|
23
|
-
"get2HTTPResponse" => "get2-http-response",
|
24
|
-
"HTTPResponseCode" => "http-response-code",
|
25
|
-
"HTTPResponseCodeXY" => "http-response-code-xy",
|
26
|
-
"supports IPv6 on iOS?" => "supports-ipv6-on-ios"
|
27
|
-
}.each do |actual, expected|
|
28
|
-
it "applies kebabcase from #{actual.inspect} to #{expected.inspect}" do
|
29
|
-
expect(Strings::Case.kebabcase(actual)).to eq(expected)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "supports unicode", if: modern_ruby? do
|
34
|
-
expect(Strings::Case.kebabcase("ЗдравствуйтеПривет")).to eq("здравствуйте-привет")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "allows to preserve acronyms" do
|
38
|
-
dashed = Strings::Case.dashcase("HTTP response code", acronyms: ["HTTP"])
|
39
|
-
|
40
|
-
expect(dashed).to eq("HTTP-response-code")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "changes a separator to :" do
|
44
|
-
dashed = Strings::Case.kebabcase("HTTP response code", separator: ":")
|
45
|
-
|
46
|
-
expect(dashed).to eq("http:response:code")
|
47
|
-
end
|
48
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#pascalcase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"f" => "F",
|
8
|
-
"1234" => "1234",
|
9
|
-
"FOO" => "Foo",
|
10
|
-
"FooBar" => "FooBar",
|
11
|
-
"fooBar" => "FooBar",
|
12
|
-
"foo bar" => "FooBar",
|
13
|
-
"Foo - Bar" => "FooBar",
|
14
|
-
"foo & bar" => "FooBar",
|
15
|
-
"FooFooBar" => "FooFooBar",
|
16
|
-
"Foo2Foo2Bar" => "Foo2Foo2Bar",
|
17
|
-
"foo-bar-baz" => "FooBarBaz",
|
18
|
-
"foo_bar_1_2" => "FooBar12",
|
19
|
-
"_foo_bar_baz_" => "FooBarBaz",
|
20
|
-
"--foo-bar--" => "FooBar",
|
21
|
-
"FOO_BAR_baz" => "FooBarBaz",
|
22
|
-
"__FOO_BAR__" => "FooBar",
|
23
|
-
"Foo w1th apo's and punc]t" => "FooW1thAposAndPunct",
|
24
|
-
"getHTTPResponse" => "GetHttpResponse",
|
25
|
-
"currencyISOCode" => "CurrencyIsoCode",
|
26
|
-
"get2HTTPResponse" => "Get2HttpResponse",
|
27
|
-
"HTTPResponseCode" => "HttpResponseCode",
|
28
|
-
"HTTPResponseCodeXY" => "HttpResponseCodeXy",
|
29
|
-
"supports IPv6 on iOS?" => "SupportsIpv6OnIos"
|
30
|
-
}.each do |actual, expected|
|
31
|
-
it "applies pascalcase to #{actual.inspect} -> #{expected.inspect}" do
|
32
|
-
expect(Strings::Case.pascalcase(actual)).to eq(expected)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "supports unicode", if: modern_ruby? do
|
37
|
-
expect(Strings::Case.pascalcase("ЗдравствуйтеПривет")).to eq("ЗдравствуйтеПривет")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to preserve acronyms" do
|
41
|
-
camelized = Strings::Case.upper_camelcase("HTTP response code", acronyms: ["HTTP"])
|
42
|
-
|
43
|
-
expect(camelized).to eq("HTTPResponseCode")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "changes a separator to :" do
|
47
|
-
camelized = Strings::Case.pascalcase("HTTP response code", separator: ":")
|
48
|
-
|
49
|
-
expect(camelized).to eq("Http:Response:Code")
|
50
|
-
end
|
51
|
-
end
|
data/spec/unit/pathcase_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#pathcase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"f" => "f",
|
8
|
-
"1234" => "1234",
|
9
|
-
"FOO" => "foo",
|
10
|
-
"FooBar" => "foo/bar",
|
11
|
-
"fooBar" => "foo/bar",
|
12
|
-
"foo bar" => "foo/bar",
|
13
|
-
"Foo - Bar" => "foo/bar",
|
14
|
-
"foo & bar" => "foo/bar",
|
15
|
-
"FooFooBar" => "foo/foo/bar",
|
16
|
-
"Foo2Foo2Bar" => "foo2/foo2/bar",
|
17
|
-
"foo-bar-baz" => "foo/bar/baz",
|
18
|
-
"foo_bar_1_2" => "foo/bar/1/2",
|
19
|
-
"_foo_bar_baz_" => "foo/bar/baz",
|
20
|
-
"--foo-bar--" => "foo/bar",
|
21
|
-
"FOO_BAR_baz" => "foo/bar/baz",
|
22
|
-
"__FOO_BAR__" => "foo/bar",
|
23
|
-
"Foo w1th apo's and punc]t" => "foo/w1th/apos/and/punct",
|
24
|
-
"getHTTPResponse" => "get/http/response",
|
25
|
-
"currencyISOCode" => "currency/iso/code",
|
26
|
-
"get2HTTPResponse" => "get2/http/response",
|
27
|
-
"HTTPResponseCode" => "http/response/code",
|
28
|
-
"HTTPResponseCodeXY" => "http/response/code/xy",
|
29
|
-
"supports IPv6 on iOS?" => "supports/ipv6/on/ios"
|
30
|
-
}.each do |actual, expected|
|
31
|
-
it "applies pathcase to #{actual.inspect} -> #{expected.inspect}" do
|
32
|
-
expect(Strings::Case.pathcase(actual)).to eq(expected)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "supports unicode", if: modern_ruby? do
|
37
|
-
expect(Strings::Case.pathcase("ЗдравствуйтеПривет")).to eq("здравствуйте/привет")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to preserve acronyms" do
|
41
|
-
pathed = Strings::Case.pathcase("HTTP response code", acronyms: ["HTTP"])
|
42
|
-
|
43
|
-
expect(pathed).to eq("HTTP/response/code")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "changes file path separator" do
|
47
|
-
pathed = Strings::Case.pathcase("HTTP response code", separator: "\\")
|
48
|
-
|
49
|
-
expect(pathed).to eq("http\\response\\code")
|
50
|
-
end
|
51
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#sentencecase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"f" => "F",
|
8
|
-
"1234" => "1234",
|
9
|
-
"FOO" => "Foo",
|
10
|
-
"FooBar" => "Foo bar",
|
11
|
-
"fooBar" => "Foo bar",
|
12
|
-
"foo bar" => "Foo bar",
|
13
|
-
"Foo - Bar" => "Foo bar",
|
14
|
-
"foo & bar" => "Foo bar",
|
15
|
-
"FooFooBar" => "Foo foo bar",
|
16
|
-
"Foo2Foo2Bar" => "Foo2 foo2 bar",
|
17
|
-
"foo-bar-baz" => "Foo bar baz",
|
18
|
-
"foo_bar_1_2" => "Foo bar 1 2",
|
19
|
-
"_foo_bar_baz_" => "Foo bar baz",
|
20
|
-
"--foo-bar--" => "Foo bar",
|
21
|
-
"FOO_BAR_baz" => "Foo bar baz",
|
22
|
-
"__FOO_BAR__" => "Foo bar",
|
23
|
-
"Foo w1th apo's and punc]t" => "Foo w1th apos and punct",
|
24
|
-
"getHTTPResponse" => "Get http response",
|
25
|
-
"currencyISOCode" => "Currency iso code",
|
26
|
-
"get2HTTPResponse" => "Get2 http response",
|
27
|
-
"HTTPResponseCode" => "Http response code",
|
28
|
-
"HTTPResponseCodeXY" => "Http response code xy",
|
29
|
-
"supports IPv6 on iOS?" => "Supports ipv6 on ios",
|
30
|
-
}.each do |actual, expected|
|
31
|
-
it "applies sentencecase to #{actual.inspect} -> #{expected.inspect}" do
|
32
|
-
expect(Strings::Case.sentencecase(actual)).to eq(expected)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "supports unicode", if: modern_ruby? do
|
37
|
-
expect(Strings::Case.sentencecase("ЗдравствуйтеПривет")).to eq("Здравствуйте привет")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to preserve acronyms" do
|
41
|
-
sentence = Strings::Case.sentencecase("HTTP response code", acronyms: ["HTTP"])
|
42
|
-
|
43
|
-
expect(sentence).to eq("HTTP response code")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "changes a separator to :" do
|
47
|
-
sentence = Strings::Case.sentencecase("HTTP response code", separator: ":")
|
48
|
-
|
49
|
-
expect(sentence).to eq("Http:response:code")
|
50
|
-
end
|
51
|
-
end
|
data/spec/unit/snakecase_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#snakecase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"f" => "f",
|
8
|
-
"1234" => "1234",
|
9
|
-
"FOO" => "foo",
|
10
|
-
"FooBar" => "foo_bar",
|
11
|
-
"fooBar" => "foo_bar",
|
12
|
-
"foo bar" => "foo_bar",
|
13
|
-
"Foo - Bar" => "foo_bar",
|
14
|
-
"foo & bar" => "foo_bar",
|
15
|
-
"FooFooBar" => "foo_foo_bar",
|
16
|
-
"Foo2Foo2Bar" => "foo2_foo2_bar",
|
17
|
-
"foo-bar-baz" => "foo_bar_baz",
|
18
|
-
"foo_bar_1_2" => "foo_bar_1_2",
|
19
|
-
"_foo_bar_baz_" => "_foo_bar_baz_",
|
20
|
-
"--foo-bar--" => "foo_bar",
|
21
|
-
"FOO_BAR_baz" => "foo_bar_baz",
|
22
|
-
"__FOO_BAR__" => "_foo_bar_",
|
23
|
-
"Foo w1th apo's and punc]t" => "foo_w1th_apos_and_punct",
|
24
|
-
"getHTTPResponse" => "get_http_response",
|
25
|
-
"currencyISOCode" => "currency_iso_code",
|
26
|
-
"get2HTTPResponse" => "get2_http_response",
|
27
|
-
"HTTPResponseCode" => "http_response_code",
|
28
|
-
"HTTPResponseCodeXY" => "http_response_code_xy",
|
29
|
-
"supports IPv6 on iOS?" => "supports_ipv6_on_ios",
|
30
|
-
}.each do |actual, expected|
|
31
|
-
it "applies snakecase to #{actual.inspect} -> #{expected.inspect}" do
|
32
|
-
expect(Strings::Case.snakecase(actual)).to eq(expected)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "supports unicode", if: modern_ruby? do
|
37
|
-
expect(Strings::Case.snakecase("ЗдравствуйтеПривет")).to eq("здравствуйте_привет")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to preserve acronyms" do
|
41
|
-
snaked = Strings::Case.underscore("HTTP response code", acronyms: ["HTTP"])
|
42
|
-
|
43
|
-
expect(snaked).to eq("HTTP_response_code")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "changes a separator to :" do
|
47
|
-
snaked = Strings::Case.snakecase("HTTP response code", separator: ":")
|
48
|
-
|
49
|
-
expect(snaked).to eq("http:response:code")
|
50
|
-
end
|
51
|
-
end
|
data/spec/unit/titlecase_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Strings::Case, "#titlecase" do
|
4
|
-
{
|
5
|
-
nil => nil,
|
6
|
-
"" => "",
|
7
|
-
"f" => "F",
|
8
|
-
"1234" => "1234",
|
9
|
-
"FOO" => "Foo",
|
10
|
-
"FooBar" => "Foo Bar",
|
11
|
-
"fooBar" => "Foo Bar",
|
12
|
-
"foo bar" => "Foo Bar",
|
13
|
-
"Foo - Bar" => "Foo Bar",
|
14
|
-
"foo & bar" => "Foo Bar",
|
15
|
-
"FooFooBar" => "Foo Foo Bar",
|
16
|
-
"Foo2Foo2Bar" => "Foo2 Foo2 Bar",
|
17
|
-
"foo-bar-baz" => "Foo Bar Baz",
|
18
|
-
"foo_bar_1_2" => "Foo Bar 1 2",
|
19
|
-
"_foo_bar_baz_" => "Foo Bar Baz",
|
20
|
-
"--foo-bar--" => "Foo Bar",
|
21
|
-
"FOO_BAR_baz" => "Foo Bar Baz",
|
22
|
-
"__FOO_BAR__" => "Foo Bar",
|
23
|
-
"Foo w1th apo's and punc]t" => "Foo W1th Apos And Punct",
|
24
|
-
"getHTTPResponse" => "Get Http Response",
|
25
|
-
"currencyISOCode" => "Currency Iso Code",
|
26
|
-
"get2HTTPResponse" => "Get2 Http Response",
|
27
|
-
"HTTPResponseCode" => "Http Response Code",
|
28
|
-
"HTTPResponseCodeXY" => "Http Response Code Xy",
|
29
|
-
"supports IPv6 on iOS?" => "Supports Ipv6 On Ios"
|
30
|
-
}.each do |actual, expected|
|
31
|
-
it "applies titlecase to #{actual.inspect} -> #{expected.inspect}" do
|
32
|
-
expect(Strings::Case.titlecase(actual)).to eq(expected)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "supports unicode", if: modern_ruby? do
|
37
|
-
expect(Strings::Case.titlecase("ЗдравствуйтеПривет")).to eq("Здравствуйте Привет")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows to preserve acronyms" do
|
41
|
-
titilized = Strings::Case.titlecase("HTTP response code", acronyms: ["HTTP"])
|
42
|
-
|
43
|
-
expect(titilized).to eq("HTTP Response Code")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "changes a separator to :" do
|
47
|
-
titilized = Strings::Case.titlecase("HTTP response code", separator: ":")
|
48
|
-
|
49
|
-
expect(titilized).to eq("Http:Response:Code")
|
50
|
-
end
|
51
|
-
end
|
data/strings-case.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
lib = File.expand_path("lib", __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "strings/case/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "strings-case"
|
7
|
-
spec.version = Strings::Case::VERSION
|
8
|
-
spec.authors = ["Piotr Murach"]
|
9
|
-
spec.email = ["me@piotrmurach.com"]
|
10
|
-
spec.summary = %q{Convert strings to different cases}
|
11
|
-
spec.description = %q{Convert strings to different cases}
|
12
|
-
spec.homepage = "https://github.com/piotrmurach/strings-case"
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
-
spec.metadata["changelog_uri"] = "https://github.com/piotrmurach/strings-case/blob/master/CHANGELOG.md"
|
17
|
-
spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/strings-case"
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/piotrmurach/strings-case"
|
20
|
-
|
21
|
-
spec.files = Dir["{lib,spec}/**/*.rb"]
|
22
|
-
spec.files += Dir["tasks/*", "strings-case.gemspec"]
|
23
|
-
spec.files += Dir["README.md", "CHANGELOG.md", "LICENSE.txt", "Rakefile"]
|
24
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = ["lib"]
|
26
|
-
|
27
|
-
spec.required_ruby_version = ">= 2.0.0"
|
28
|
-
|
29
|
-
spec.add_development_dependency "bundler", ">= 1.5"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
begin
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
|
6
|
-
desc "Run all specs"
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = "spec/{unit,integration}{,/*/**}/*_spec.rb"
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc "Run unit specs"
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = "spec/unit{,/*/**}/*_spec.rb"
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Run integration specs"
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = "spec/integration{,/*/**}/*_spec.rb"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|