Class: Compendium::ResultSet
- Inherits:
-
Object
- Object
- Compendium::ResultSet
- Defined in:
- lib/compendium/result_set.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
(also: #all)
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(records) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #keys ⇒ Object
Constructor Details
#initialize(records) ⇒ ResultSet
Returns a new instance of ResultSet.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/compendium/result_set.rb', line 11 def initialize(records) @records = if records.respond_to?(:map) records.map do |r| r.respond_to?(:with_indifferent_access) ? r.with_indifferent_access : r end else [records] end @records = Hash[@records] if records.is_a?(Hash) end |
Instance Attribute Details
#records ⇒ Object (readonly) Also known as: all
Returns the value of attribute records.
8 9 10 |
# File 'lib/compendium/result_set.rb', line 8 def records @records end |
Instance Method Details
#as_json(options = {}) ⇒ Object
27 28 29 |
# File 'lib/compendium/result_set.rb', line 27 def as_json( = {}) records.map{ |r| r.except(*[:except]) } end |
#keys ⇒ Object
23 24 25 |
# File 'lib/compendium/result_set.rb', line 23 def keys records.is_a?(Array) ? first.keys : records.keys end |