caseninja 0.0.1
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/.gitignore +14 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +9 -0
- data/bin/caseninja +40 -0
- data/caseninja.gemspec +24 -0
- data/lib/caseninja.rb +53 -0
- data/lib/caseninja/version.rb +3 -0
- data/test/minitest_helper.rb +4 -0
- data/test/test_caseninja.rb +45 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e6a96a58e2541025b9a362f3afae008e35da385
|
4
|
+
data.tar.gz: 86082e022334d2fffe6d6edef43cb43bb5424f06
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0deb50187f567539a659896a8db6efe1aab12e906b9da1f876860ca5078f5086832de3a6f8e22fd8674acacc41c3356a34023538c2858c9859838fbaaf1cf242
|
7
|
+
data.tar.gz: 4f589ab249fc7b0f506f81c534d46cde7db81e6cf509f9509f5f35a505205dd68cf2ff601a1535233eabdb61e601a45b934312709d9bdfb0b6f58ff856709136
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 ongaeshi
|
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/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Caseninja
|
2
|
+
|
3
|
+
Caseninja converts input text to chain, snake, camel and pascal case. It will freely convert any text to any case.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
$ gem install caseninja
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
$ caseninja
|
15
|
+
Usage: caseninja [options] args
|
16
|
+
--chain Convert to chain case
|
17
|
+
--snake Convert to snake case
|
18
|
+
--camel Convert to camel case
|
19
|
+
--pascal Convert to pascal case
|
20
|
+
--upchain Convert to upper chain case
|
21
|
+
--upsnake Convert to upper snake case
|
22
|
+
```
|
23
|
+
|
24
|
+
Convert the entered text to the chain, snake, camel, pascal, uppercase chain and uppercase snake.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ caseninja "hello world"
|
28
|
+
hello-world # chain
|
29
|
+
hello_world # snake
|
30
|
+
helloWorld # camel
|
31
|
+
HelloWorld # pascal
|
32
|
+
HELLO-WORLD # upchain
|
33
|
+
HELLO_WORLD # upsnake
|
34
|
+
```
|
35
|
+
|
36
|
+
You can enter all the case.
|
37
|
+
|
38
|
+
```
|
39
|
+
$ caseninja fooBarToBaz
|
40
|
+
foo-bar-to-baz
|
41
|
+
foo_bar_to_baz
|
42
|
+
fooBarToBaz
|
43
|
+
FooBarToBaz
|
44
|
+
FOO-BAR-TO-BAZ
|
45
|
+
FOO_BAR_TO_BAZ
|
46
|
+
|
47
|
+
$ caseninja foo-bar-to-baz
|
48
|
+
foo-bar-to-baz
|
49
|
+
foo_bar_to_baz
|
50
|
+
fooBarToBaz
|
51
|
+
FooBarToBaz
|
52
|
+
FOO-BAR-TO-BAZ
|
53
|
+
FOO_BAR_TO_BAZ
|
54
|
+
```
|
55
|
+
|
56
|
+
Convert to snake case.
|
57
|
+
|
58
|
+
```
|
59
|
+
$ caseninja fooBarToBaz --snake
|
60
|
+
foo_bar_to_baz
|
61
|
+
```
|
62
|
+
|
63
|
+
Convert to snake and pascal case.
|
64
|
+
|
65
|
+
```
|
66
|
+
$ caseninja fooBarToBaz -s -p
|
67
|
+
foo_bar_to_baz
|
68
|
+
FooBarToBaz
|
69
|
+
```
|
70
|
+
|
71
|
+
You can also pass the sentence.
|
72
|
+
|
73
|
+
```
|
74
|
+
$ caseninja "What does the Japanese word Dattebayo mean?"
|
75
|
+
what-does-the-japanese-word-dattebayo-mean?
|
76
|
+
what_does_the_japanese_word_dattebayo_mean?
|
77
|
+
whatDoesTheJapaneseWordDattebayoMean?
|
78
|
+
WhatDoesTheJapaneseWordDattebayoMean?
|
79
|
+
WHAT-DOES-THE-JAPANESE-WORD-DATTEBAYO-MEAN?
|
80
|
+
WHAT_DOES_THE_JAPANESE_WORD_DATTEBAYO_MEAN?
|
81
|
+
```
|
data/Rakefile
ADDED
data/bin/caseninja
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'caseninja'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
Version = Caseninja::VERSION
|
7
|
+
|
8
|
+
opts = {}
|
9
|
+
|
10
|
+
ARGV.options do |o|
|
11
|
+
o.banner = "Usage: caseninja [options] args"
|
12
|
+
|
13
|
+
o.on("--chain", "Convert to chain case") { opts[:chain] = true }
|
14
|
+
o.on("--snake", "Convert to snake case") { opts[:snake] = true }
|
15
|
+
o.on("--camel", "Convert to camel case") { opts[:camel] = true }
|
16
|
+
o.on("--pascal", "Convert to pascal case") { opts[:pascal] = true }
|
17
|
+
o.on("--upchain", "Convert to upper chain case") { opts[:upchain] = true }
|
18
|
+
o.on("--upsnake", "Convert to upper snake case") { opts[:upsnake] = true }
|
19
|
+
|
20
|
+
o.parse!
|
21
|
+
end
|
22
|
+
|
23
|
+
if ARGV.count == 0
|
24
|
+
puts ARGV.options.help
|
25
|
+
else
|
26
|
+
ARGV.each do |text|
|
27
|
+
if opts.empty?
|
28
|
+
puts Caseninja.to_hash(text).values
|
29
|
+
else
|
30
|
+
puts Caseninja.to_chain(text) if opts[:chain]
|
31
|
+
puts Caseninja.to_snake(text) if opts[:snake]
|
32
|
+
puts Caseninja.to_pascal(text) if opts[:pascal]
|
33
|
+
puts Caseninja.to_camel(text) if opts[:camel]
|
34
|
+
puts Caseninja.to_upchain(text) if opts[:upchain]
|
35
|
+
puts Caseninja.to_upsnake(text) if opts[:upsnake]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
data/caseninja.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'caseninja/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "caseninja"
|
8
|
+
spec.version = Caseninja::VERSION
|
9
|
+
spec.authors = ["ongaeshi"]
|
10
|
+
spec.email = ["ongaeshi0621@gmail.com"]
|
11
|
+
spec.summary = %q{Convert input text to chain, snake, camel and pascal case.}
|
12
|
+
spec.description = %q{Caseninja converts input text to chain, snake, camel and pascal case. It will freely convert any text to any case.}
|
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
|
+
spec.add_development_dependency "minitest"
|
24
|
+
end
|
data/lib/caseninja.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "caseninja/version"
|
2
|
+
|
3
|
+
module Caseninja
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def to_hash(text)
|
7
|
+
{
|
8
|
+
chain: to_chain(text),
|
9
|
+
snake: to_snake(text),
|
10
|
+
camel: to_camel(text),
|
11
|
+
pascal: to_pascal(text),
|
12
|
+
upchain: to_upchain(text),
|
13
|
+
upsnake: to_upsnake(text),
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_chain(text)
|
18
|
+
normalize(text).gsub(" ", "-")
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_snake(text)
|
22
|
+
normalize(text).gsub(" ", "_")
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_camel(text)
|
26
|
+
to_pascal(text).sub(/./) { $&.downcase }
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_pascal(text)
|
30
|
+
normalize(text).split.map { |e| e.capitalize }.join
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_upchain(text)
|
34
|
+
to_chain(text).upcase
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_upsnake(text)
|
38
|
+
to_snake(text).upcase
|
39
|
+
end
|
40
|
+
|
41
|
+
def normalize(text)
|
42
|
+
if text =~ / /
|
43
|
+
text.downcase
|
44
|
+
elsif text =~ /-/
|
45
|
+
text.gsub("-", " ").downcase
|
46
|
+
elsif text =~ /_/
|
47
|
+
text.gsub("_", " ").downcase
|
48
|
+
else
|
49
|
+
text.split(/(?=[A-Z])/).join(" ").downcase
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class TestCaseninja < MiniTest::Test
|
4
|
+
def test_that_it_has_a_version_number
|
5
|
+
refute_nil ::Caseninja::VERSION
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_to_hash
|
9
|
+
assert_equal(
|
10
|
+
{
|
11
|
+
chain: "hello-world",
|
12
|
+
snake: "hello_world",
|
13
|
+
camel: "helloWorld",
|
14
|
+
pascal: "HelloWorld",
|
15
|
+
upchain: "HELLO-WORLD",
|
16
|
+
upsnake: "HELLO_WORLD",
|
17
|
+
},
|
18
|
+
Caseninja.to_hash("hello world")
|
19
|
+
)
|
20
|
+
|
21
|
+
assert_equal(
|
22
|
+
{
|
23
|
+
chain: "caseninja-converts-input-text-to-chain-case",
|
24
|
+
snake: "caseninja_converts_input_text_to_chain_case",
|
25
|
+
camel: "caseninjaConvertsInputTextToChainCase",
|
26
|
+
pascal: "CaseninjaConvertsInputTextToChainCase",
|
27
|
+
upchain: "CASENINJA-CONVERTS-INPUT-TEXT-TO-CHAIN-CASE",
|
28
|
+
upsnake: "CASENINJA_CONVERTS_INPUT_TEXT_TO_CHAIN_CASE",
|
29
|
+
},
|
30
|
+
Caseninja.to_hash("Caseninja converts input text to chain case")
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_normlize
|
35
|
+
assert_equal "hello world", Caseninja.normalize("hello world")
|
36
|
+
assert_equal "hello world", Caseninja.normalize("Hello world")
|
37
|
+
assert_equal "hello world", Caseninja.normalize("hello-world")
|
38
|
+
assert_equal "hello world", Caseninja.normalize("hello_world")
|
39
|
+
assert_equal "hello world", Caseninja.normalize("helloWorld")
|
40
|
+
assert_equal "hello world", Caseninja.normalize("HelloWorld")
|
41
|
+
assert_equal "hello world", Caseninja.normalize("HELLO-WORLD")
|
42
|
+
assert_equal "hello world", Caseninja.normalize("HELLO_WORLD")
|
43
|
+
assert_equal "hello world", Caseninja.normalize("HELLO_world")
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: caseninja
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ongaeshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-29 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Caseninja converts input text to chain, snake, camel and pascal case.
|
56
|
+
It will freely convert any text to any case.
|
57
|
+
email:
|
58
|
+
- ongaeshi0621@gmail.com
|
59
|
+
executables:
|
60
|
+
- caseninja
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/caseninja
|
71
|
+
- caseninja.gemspec
|
72
|
+
- lib/caseninja.rb
|
73
|
+
- lib/caseninja/version.rb
|
74
|
+
- test/minitest_helper.rb
|
75
|
+
- test/test_caseninja.rb
|
76
|
+
homepage: ''
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Convert input text to chain, snake, camel and pascal case.
|
100
|
+
test_files:
|
101
|
+
- test/minitest_helper.rb
|
102
|
+
- test/test_caseninja.rb
|