Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support symbols/strings with spaces. #76

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/enumerate_it/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def register_enumeration(values_hash)
end

def define_enumeration_constant(name, value)
const_set name.to_s.tr('-', '_').upcase, value
const_set name.to_s.tr('-', '_').gsub(/\p{blank}/, '_').upcase, value
end

def values_hash(args)
Expand Down
4 changes: 4 additions & 0 deletions spec/enumerate_it/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
expect(TestEnumerationWithDash::PT_BR).to eq('pt-BR')
end

it 'creates constants for values with spaces' do
expect(TestEnumerationWithSpaces::SPA_CES).to eq('spa ces')
end

describe '.list' do
it "creates a method that returns the allowed values in the enumeration's class" do
expect(TestEnumeration.list).to eq(%w[1 2 3])
Expand Down
4 changes: 4 additions & 0 deletions spec/support/test_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class TestEnumerationWithCamelCase < EnumerateIt::Base
associate_values 'iPhone'
end

class TestEnumerationWithSpaces < EnumerateIt::Base
associate_values 'spa ces'
end

class Foobar < EnumerateIt::Base
associate_values bar: 'foo'
end
Expand Down