Skip to content

Commit

Permalink
Added Link#id utility method.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed Jul 17, 2014
1 parent cffbf5d commit 5f00703
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/kosapi_client/entity/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def self.parse(contents, context = {})
href = contents[:xlink_href] || contents[:href]
new(contents[:__content__], href, contents[:rel])
end

def id
@href.split('/').last
end

end
end
end
12 changes: 10 additions & 2 deletions spec/kosapi_client/entity/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@

Link = KOSapiClient::Entity::Link

subject(:link) { Link.parse({href: 'http://example.com', __content__: 'Example Site', rel: 'next'}) }
subject(:link) { Link.parse({href: 'http://example.com/foo/bar/42', __content__: 'Example Site', rel: 'next'}) }

describe '.parse' do

it 'can be parsed from a hash' do
expect(link.href).to eq 'http://example.com'
expect(link.href).to eq 'http://example.com/foo/bar/42'
expect(link.title).to eq 'Example Site'
expect(link.rel).to eq 'next'
end

end

describe '#id' do

it 'returns last href segment' do
expect(link.id).to eq '42'
end

end

end

0 comments on commit 5f00703

Please sign in to comment.