Class: Corelogic::Collection
- Inherits:
-
Object
- Object
- Corelogic::Collection
- Extended by:
- Forwardable
- Defined in:
- lib/corelogic/collection.rb
Constant Summary collapse
- DEFAULT_RECORDS_LIMIT =
10
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#limit_value ⇒ Object
readonly
Returns the value of attribute limit_value.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#raw_hash ⇒ Object
readonly
Returns the value of attribute raw_hash.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
-
#initialize(klass, raw_hash) ⇒ Collection
constructor
A new instance of Collection.
- #to_a ⇒ Object
Constructor Details
#initialize(klass, raw_hash) ⇒ Collection
Returns a new instance of Collection.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/corelogic/collection.rb', line 9 def initialize(klass, raw_hash) @klass = klass.is_a?(::String) ? ::Object.const_get(klass) : klass @raw_hash = raw_hash @total_pages = raw_hash[:totalPages] || 1 @current_page = raw_hash[:pageNumber] || 1 @limit_value = raw_hash[:pageSize] || DEFAULT_RECORDS_LIMIT @total_records = raw_hash[:totalRecords] if !@raw_hash[:data].nil? && !@raw_hash[:data].empty? @members = @raw_hash[:data].map do |record| @klass.new(record) end else @members = [] end end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def current_page @current_page end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def klass @klass end |
#limit_value ⇒ Object (readonly)
Returns the value of attribute limit_value.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def limit_value @limit_value end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def members @members end |
#raw_hash ⇒ Object (readonly)
Returns the value of attribute raw_hash.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def raw_hash @raw_hash end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def total_pages @total_pages end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records.
7 8 9 |
# File 'lib/corelogic/collection.rb', line 7 def total_records @total_records end |
Instance Method Details
#to_a ⇒ Object
27 28 29 |
# File 'lib/corelogic/collection.rb', line 27 def to_a @members end |