Class: Everypolitician::Popolo::Collection
- Inherits:
-
Object
- Object
- Everypolitician::Popolo::Collection
show all
- Includes:
- Enumerable
- Defined in:
- lib/everypolitician/popolo/collection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(documents) ⇒ Collection
Returns a new instance of Collection.
8
9
10
|
# File 'lib/everypolitician/popolo/collection.rb', line 8
def initialize(documents)
@documents = documents ? documents.map { |p| klass.new(p) } : []
end
|
Instance Attribute Details
#documents ⇒ Object
Returns the value of attribute documents.
6
7
8
|
# File 'lib/everypolitician/popolo/collection.rb', line 6
def documents
@documents
end
|
Instance Method Details
#-(other) ⇒ Object
16
17
18
19
|
# File 'lib/everypolitician/popolo/collection.rb', line 16
def -(other)
other_ids = Set.new(other.documents.map(&:id))
documents.reject { |d| other_ids.include?(d.id) }
end
|
#each(&block) ⇒ Object
12
13
14
|
# File 'lib/everypolitician/popolo/collection.rb', line 12
def each(&block)
documents.each(&block)
end
|
#find_by(attributes = {}) ⇒ Object
21
22
23
|
# File 'lib/everypolitician/popolo/collection.rb', line 21
def find_by(attributes = {})
where(attributes).first
end
|
#where(attributes = {}) ⇒ Object
25
26
27
28
29
|
# File 'lib/everypolitician/popolo/collection.rb', line 25
def where(attributes = {})
find_all do |object|
attributes.all? { |k, v| object.send(k) == v }
end
end
|