Skip to content

Commit

Permalink
Added full_name convenience method to base_person.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed Aug 21, 2014
1 parent ff944ad commit dc331d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/kosapi_client/entity/base_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class BasePerson < BaseEntity
map_data :titles_pre
map_data :username

def full_name
prefix = "#{titles_pre} " if titles_pre
suffix = " #{titles_post}" if titles_post
"#{prefix}#{first_name} #{last_name}#{suffix}"
end

end
end
end
19 changes: 19 additions & 0 deletions spec/kosapi_client/entity/base_person_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'

describe KOSapiClient::Entity::BasePerson do

describe '#full_name' do

it 'returns whole name with titles' do
person = described_class.parse(first_name: 'Foo', last_name: 'Bar', titles_pre: 'Ing.', titles_post: 'Ph.D.')
expect(person.full_name).to eq 'Ing. Foo Bar Ph.D.'
end

it 'skips title if not set' do
person = described_class.parse(first_name: 'Foo', last_name: 'Bar', titles_pre: 'Ing.')
expect(person.full_name).to eq 'Ing. Foo Bar'
end

end

end

0 comments on commit dc331d1

Please sign in to comment.