strings-case 0.1.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/CHANGELOG.md +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +317 -0
- data/Rakefile +8 -0
- data/lib/strings-case.rb +1 -0
- data/lib/strings/case.rb +304 -0
- data/lib/strings/case/extensions.rb +50 -0
- data/lib/strings/case/version.rb +7 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/unit/camelcase_spec.rb +51 -0
- data/spec/unit/constcase_spec.rb +44 -0
- data/spec/unit/extensions_spec.rb +75 -0
- data/spec/unit/headercase_spec.rb +50 -0
- data/spec/unit/kebabcase_spec.rb +48 -0
- data/spec/unit/pascalcase_spec.rb +51 -0
- data/spec/unit/pathcase_spec.rb +51 -0
- data/spec/unit/sentencecase_spec.rb +51 -0
- data/spec/unit/snakecase_spec.rb +51 -0
- data/spec/unit/titlecase_spec.rb +51 -0
- data/strings-case.gemspec +32 -0
- data/tasks/console.rake +11 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/spec.rake +29 -0
- metadata +113 -0
@@ -0,0 +1,51 @@
|
|
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
|
@@ -0,0 +1,51 @@
|
|
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
|
@@ -0,0 +1,51 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
ADDED
data/tasks/coverage.rake
ADDED
data/tasks/spec.rake
ADDED
@@ -0,0 +1,29 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strings-case
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piotr Murach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Convert strings to different cases
|
56
|
+
email:
|
57
|
+
- me@piotrmurach.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- CHANGELOG.md
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/strings-case.rb
|
67
|
+
- lib/strings/case.rb
|
68
|
+
- lib/strings/case/extensions.rb
|
69
|
+
- lib/strings/case/version.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/unit/camelcase_spec.rb
|
72
|
+
- spec/unit/constcase_spec.rb
|
73
|
+
- spec/unit/extensions_spec.rb
|
74
|
+
- spec/unit/headercase_spec.rb
|
75
|
+
- spec/unit/kebabcase_spec.rb
|
76
|
+
- spec/unit/pascalcase_spec.rb
|
77
|
+
- spec/unit/pathcase_spec.rb
|
78
|
+
- spec/unit/sentencecase_spec.rb
|
79
|
+
- spec/unit/snakecase_spec.rb
|
80
|
+
- spec/unit/titlecase_spec.rb
|
81
|
+
- strings-case.gemspec
|
82
|
+
- tasks/console.rake
|
83
|
+
- tasks/coverage.rake
|
84
|
+
- tasks/spec.rake
|
85
|
+
homepage: https://github.com/piotrmurach/strings-case
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
allowed_push_host: https://rubygems.org
|
90
|
+
changelog_uri: https://github.com/piotrmurach/strings-case/blob/master/CHANGELOG.md
|
91
|
+
documentation_uri: https://www.rubydoc.info/gems/strings-case
|
92
|
+
homepage_uri: https://github.com/piotrmurach/strings-case
|
93
|
+
source_code_uri: https://github.com/piotrmurach/strings-case
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.0.0
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.0.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Convert strings to different cases
|
113
|
+
test_files: []
|