Skip to content

Commit 30a3d49

Browse files
committed
feat: SerpParser::Collection
1 parent 67477d2 commit 30a3d49

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/serp_parser/collection.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require "forwardable"
2+
3+
module SerpParser
4+
class Collection
5+
include Enumerable
6+
extend Forwardable
7+
8+
def_delegators :@items, :size, :length, :[], :empty?, :last, :index
9+
10+
def initialize(items)
11+
@items = items
12+
end
13+
14+
def each(&block)
15+
@items.each(&block)
16+
end
17+
end
18+
end

lib/serp_parser/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run_schema
4747
# @return [Array] The collection of data.
4848
def build_collection(parsers)
4949
results = parse_children(parsers)
50-
results
50+
SerpParser::Collection.new(results)
5151
end
5252

5353
# Extracts data from the document and merges it into a single hash.

spec/serp_parser/google/search_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
end
2626

2727
describe "#organic_results" do
28-
it "returns an array of organic results" do
28+
it "returns a collection object" do
29+
expect(parser.organic_results).to be_an_instance_of(SerpParser::Collection)
30+
end
31+
32+
it "returns organic results" do
2933
expect(parser.organic_results).to all(be_an_instance_of(SerpParser::Models::OrganicResult))
3034
end
3135

0 commit comments

Comments
 (0)