Skip to content

Commit

Permalink
Remove Streamer#find
Browse files Browse the repository at this point in the history
Let the user deal with traversing the hash
  • Loading branch information
hakanensari committed Jul 11, 2012
1 parent 5225215 commit 6581009
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 51 deletions.
25 changes: 0 additions & 25 deletions lib/jeff/streamer.rb
Expand Up @@ -11,31 +11,6 @@ def call(chunk, remaining_bytes, total_bytes)
@parser.finish if remaining_bytes == 0
end

# Queries response for a key.
#
# key - A String key.
#
# Returns an Array of matches.
def find(key, node = nil)
node ||= root

case node
when Array
node
.map { |val| find key, val }
.compact
.flatten
when Hash
if node.has_key? key
[node[key]]
else
node
.values
.map { |val| find key, val }
.compact
.flatten
end
end
def document
@parser.document
end
Expand Down
27 changes: 1 addition & 26 deletions spec/jeff/streamer_spec.rb
Expand Up @@ -8,14 +8,7 @@ module Jeff
%{
<?xml version="1.0" ?>
<foo>
<bar>
<baz>1</baz>
<qux>2</qux>
<qux>3</qux>
</bar>
<quux>
<qux>4</qux>
</quux>
<bar>1</bar>
</foo>
}.strip.gsub />\s+</, '><'
end
Expand All @@ -31,23 +24,5 @@ module Jeff

streamer.root.should have_key 'foo'
end

describe '#find' do
before do
streamer.call xml, 0, xml.size
end

it 'should find a node' do
streamer.find('baz').should eql ['1']
end

it 'should find a collection of nodes' do
streamer.find('qux').should eql ['2', '3', '4']
end

it 'should be empty if no matches found' do
streamer.find('corge').should be_empty
end
end
end
end

0 comments on commit 6581009

Please sign in to comment.