Class: LearnSprout::Page
- Inherits:
-
Object
- Object
- LearnSprout::Page
- Includes:
- Connection
- Defined in:
- lib/learnsprout/page.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(url, type, extras = {}) ⇒ Page
constructor
A new instance of Page.
- #next ⇒ Object
Constructor Details
#initialize(url, type, extras = {}) ⇒ Page
Returns a new instance of Page.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/learnsprout/page.rb', line 7 def initialize(url, type, extras = {}) @items = [] @type = type @extras = extras data = get(url) @nextUrl = data["next"].to_s # Remove base URL if it's included prefix = LearnSprout.endpoint.to_s if @nextUrl[0, prefix.length] == prefix @nextUrl = @nextUrl[prefix.length, @nextUrl.length - prefix.length] end #TODO handle non-page URL? data["data"].each do |item| extras.each do |key, value| item[key] = value end @items << type.new(item) end end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/learnsprout/page.rb', line 5 def items @items end |