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

fix the possessive call when calling twice with another method argument #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ require 'active_record'
require 'active_model'
```

## Run tests with

`bundle exec rake test`

## No further development is going to happen

This gem is essentially frozen, as the developers have decided to only deal with full names going forward in their applications. Feel free to fork this work, brand it under a new name, and continue development.
Expand Down
10 changes: 5 additions & 5 deletions lib/name_of_person/person_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ def sorted
@sorted ||= last.present? ? "#{last}, #{first}" : first
end

# Returns full name with with trailing 's or ' if name ends in s.
# Returns full name with trailing 's or ' if name ends in s.
def possessive(method = :full)
whitelist = %i[full first last abbreviated sorted initials]
allowed_method_names = %i[full first last abbreviated sorted initials]

unless whitelist.include?(method.to_sym)
unless allowed_method_names.include?(method.to_sym)
raise ArgumentError, 'Please provide a valid method'
end

name = public_send(method)

@possessive ||= "#{name}'#{'s' unless name.downcase.end_with?('s')}"
"#{name}'#{'s' unless name.downcase.end_with?('s')}"
end

# Returns just the initials.
def initials
@initials ||= remove(/(\(|\[).*(\)|\])/).scan(/([[:word:]])[[:word:]]*/i).join
end

# Returns a mentionable version of the familiar name
# Returns a mentionable version of the familiar name.
def mentionable
@mentionable ||= familiar.chop.delete(' ').downcase
end
Expand Down
3 changes: 2 additions & 1 deletion test/person_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PersonNameTest < ActiveSupport::TestCase

test "possessive" do
assert_equal "#{@name.full}'s", @name.possessive
assert_equal "#{@name.initials}'s", @name.possessive(:initials)
assert_equal "#{@first.full}'s", @first.possessive
assert_equal "Foo Bars'", PersonName.new('Foo', 'Bars').possessive
end
Expand All @@ -71,7 +72,7 @@ class PersonNameTest < ActiveSupport::TestCase
test "possessive initials" do
assert_equal "#{@name.initials}'s", @name.possessive(:initials)
end

test "possessive abbreviated" do
assert_equal "#{@name.abbreviated}'s", @name.possessive(:abbreviated)
end
Expand Down