Skip to content

Commit

Permalink
Merge pull request #15 from benSlaughter/add-kebab-case
Browse files Browse the repository at this point in the history
Add kebab case. Version 1.3.0.
  • Loading branch information
benSlaughter authored Aug 15, 2018
2 parents fb6f7d7 + 7961c31 commit e4aceb2
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 12 deletions.
15 changes: 11 additions & 4 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# History
## Released Versions
### Version 1.3.0
#### Minor: Added kebab-case
* Added kebab case tests
* Added kebab case backwards compatibility tests
* Added kebab case method for strings
* Updated split regex to include hyphen

### Versions 1.2.0
#### Minor: Fixed dependency vulnerabilities
* Updated readme
Expand All @@ -9,16 +16,16 @@


### Version 1.1.0
#### Minor: Added functionality to modify hash keys
#### Minor: Added functionality to modify hash keys
* Added string keys to hash
* Added symbol keys to hash
* Updated fixnum to integer as per rubocop rules

### Version 1.0.0
#### Major: Adding lower option to the camel method
* Adding the lower option for the first character in the "camel" method
* Fixing rubocop offenses
* Fixing rubocop offenses

### Version 0.6.2
#### Patch: Transform keys update
* Updated transform keys method as when used with active record it clashes
Expand All @@ -36,7 +43,7 @@
* Fixed camelCase methods
* Fixed several rubocop errors
* Removed .rb from file requires

### Version 0.4.1
#### Patch: Added string modify module
* Added new string methods for updating a string
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ false.bool?
'snake_case'.camel
=> 'SnakeCase'

'snake_case'.camel(:lower)
=> 'snakeCase'
'kebab-case'.camel(:lower)
=> 'kebabCase'

'space case'.snake
=> 'space_case'

'CamelCase'.space
=> 'camel case'

'camelCase'.kebab
=> 'camel-case'
```
10 changes: 8 additions & 2 deletions lib/utilise/augment/modify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ def space
split_up.join(' ')
end

# Returns a string in kebab case
def kebab
split_up.join('-')
end

private

# Splits up the current string into an array and normalises it
def split_up
regex = /(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?=_)|(?= )/
regex = /(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?=[-_ ])/
arr = to_s.split(regex)
arr.map!(&:downcase)
arr.map!(&:strip)
arr.map { |s| s.delete('_') }
arr.map! { |s| s.delete('_') }
arr.map { |s| s.delete('-') }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/utilise/version.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Utilise
module Utilise
# The current gem version
VERSION = '1.2.0'.freeze
VERSION = '1.3.0'.freeze
# The version update date
DATE = '2018-01-03'.freeze
DATE = '2018-08-15'.freeze
# Debug output message
MSG = 'Version %<version>s %<date>s (running on %<engine>s-%<ruby>s)'.freeze

Expand Down
50 changes: 50 additions & 0 deletions spec/utilise/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
it 'returns a camel case from complex camel case' do
expect('CamelONECase'.camel).to eq 'CamelOneCase'
end

it 'returns a camel case from camel case' do
expect('camel-case'.camel).to eq 'CamelCase'
end
end

context 'lower option' do
Expand Down Expand Up @@ -102,6 +106,10 @@
it 'returns a camel case from complex camel case' do
expect('CamelONECase'.camel(:lower)).to eq 'camelOneCase'
end

it 'returns a camel case from camel case' do
expect('camel-case'.camel(:lower)).to eq 'camelCase'
end
end
end

Expand Down Expand Up @@ -133,6 +141,10 @@
it 'returns a snake case from complex camel case' do
expect('SnakeONECase'.snake).to eq 'snake_one_case'
end

it 'returns a snake case from snake case' do
expect('snake-case'.snake).to eq 'snake_case'
end
end

describe '#space' do
Expand Down Expand Up @@ -163,5 +175,43 @@
it 'returns a space case from complex camel case' do
expect('SpaceONECase'.space).to eq 'space one case'
end

it 'returns a space case from space case' do
expect('space-case'.space).to eq 'space case'
end
end

describe '#kebab' do
it 'returns a kebab case from camel case' do
expect('KebabCase'.kebab).to eq 'kebab-case'
end

it 'returns a kebab case from numeric camel case' do
expect('KebabCase'.kebab).to eq 'kebab-case'
end

it 'returns a kebab case from snake case' do
expect('kebab_case'.kebab).to eq 'kebab-case'
end

it 'returns a kebab case from numeric snake case' do
expect('kebab1_case'.kebab).to eq 'kebab1-case'
end

it 'returns a kebab case from space case' do
expect('kebab case'.kebab).to eq 'kebab-case'
end

it 'returns a kebab case from numeric space case' do
expect('kebab1 case'.kebab).to eq 'kebab1-case'
end

it 'returns a kebab case from complex camel case' do
expect('KebabONECase'.kebab).to eq 'kebab-one-case'
end

it 'returns a kebab case from kebab case' do
expect('kebab-case'.kebab).to eq 'kebab-case'
end
end
end
2 changes: 1 addition & 1 deletion spec/utilise/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Utilise do
describe '.version' do
it 'should return the current gem version' do
expect(Utilise.version).to eq('1.2.0')
expect(Utilise.version).to eq('1.3.0')
end

it 'should return the current gem version with debug information' do
Expand Down
2 changes: 1 addition & 1 deletion utilise.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'utilise/version'

Expand Down

0 comments on commit e4aceb2

Please sign in to comment.