Skip to content

Commit

Permalink
fix for composed state names
Browse files Browse the repository at this point in the history
  • Loading branch information
Estebes10 committed Apr 29, 2022
1 parent 0c7ca69 commit f833c29
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.1.1] - 2022-04-29
### Fixed
- Bug in state composed names.

## [1.1.0] - 2022-04-20
### Added
- Support for multiple state and gender ids.

### Fixed
- Bug in last names composed only with consonants.
- Improved code maintainability.

## [1.0.0] - 2020-11-03

Expand Down
5 changes: 3 additions & 2 deletions lib/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def error_message!
def parse_attribute(attribute)
return if blank_string?(attribute)

str = remove_special_chars(normalize(attribute))
str = remove_special_chars(attribute)
remove_composed_names(str)
end

Expand All @@ -31,7 +31,8 @@ def blank_string?(value)
end

def remove_special_chars(string)
string&.gsub(/[.'\d-]/, "")
normalized = normalize(string)
normalized&.gsub(/[.'\d-]/, "")
end

def normalize(string)
Expand Down
2 changes: 1 addition & 1 deletion lib/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CurpGenerator::State < CurpGenerator::Base
include CurpGenerator::Catalogs

def initialize(birth_state)
@birth_state = parse_attribute(birth_state&.upcase)
@birth_state = remove_special_chars(birth_state&.upcase)
end

def self.generate(birth_state)
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CurpGenerator
VERSION = '1.1.0'.freeze
VERSION = '1.1.1'.freeze
end
12 changes: 12 additions & 0 deletions spec/unit/state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
expect(subject.generate.size).to eq(2)
end
end

context 'and composed name' do
let(:state) { 'CIUDAD DE MEXICO' }

it 'returns state characters' do
expect(subject.generate).to eq('DF')
end

it 'returns two characters' do
expect(subject.generate.size).to eq(2)
end
end
end

context 'when is a foreign location' do
Expand Down

0 comments on commit f833c29

Please sign in to comment.