Class: Coach4rb::Resource::Page
- Inherits:
-
Object
- Object
- Coach4rb::Resource::Page
- Includes:
- Mixin::AsHash, Mixin::AutoConstructor, Mixin::Iterable, Enumerable
- Defined in:
- lib/coach4rb/resource/page.rb
Instance Attribute Summary (collapse)
-
- (Object) available
Returns the value of attribute available.
-
- (Object) end
Returns the value of attribute end.
-
- (Object) links
Returns the value of attribute links.
-
- (Object) start
Returns the value of attribute start.
-
- (Object) type
Returns the value of attribute type.
-
- (Object) uri
Returns the value of attribute uri.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) [](key)
- - (Object) each(&block)
- - (Object) entities (also: #items)
- - (Object) size
- - (Object) to_a
Methods included from Mixin::AsHash
Methods included from Mixin::Iterable
Methods included from Mixin::AutoConstructor
Instance Attribute Details
- (Object) available
Returns the value of attribute available
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def available @available end |
- (Object) end
Returns the value of attribute end
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def end @end end |
- (Object) links
Returns the value of attribute links
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def links @links end |
- (Object) start
Returns the value of attribute start
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def start @start end |
- (Object) type
Returns the value of attribute type
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def type @type end |
- (Object) uri
Returns the value of attribute uri
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def uri @uri end |
Class Method Details
+ (Object) from_coach(a_hash, entity_class = Entity)
14 15 16 17 18 19 20 21 22 |
# File 'lib/coach4rb/resource/page.rb', line 14 def self.from_coach(a_hash, entity_class=Entity) new_hash = a_hash.dup type_plural = pluralize(new_hash[:type]) if new_hash[:type] type_plural ||= false new_hash[:links] ||= [] new_hash[:type] = type_plural new_hash[:entity_class] ||= entity_class self.new new_hash end |
Instance Method Details
- (Object) [](key)
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/coach4rb/resource/page.rb', line 41 def [](key) case key when Integer entities[key] when Symbol super(key) else raise 'Error: param not supported!' end end |
- (Object) each(&block)
53 54 55 56 57 |
# File 'lib/coach4rb/resource/page.rb', line 53 def each(&block) entities.each do |item| block.call item end end |
- (Object) entities Also known as: items
25 26 27 28 29 30 31 32 |
# File 'lib/coach4rb/resource/page.rb', line 25 def entities if @type && @entities.nil? hashes = instance_variable_get("@#{@type}") @entities = hashes.map { |a_hash| @entity_class.from_coach a_hash } else @entities end end |
- (Object) size
36 37 38 |
# File 'lib/coach4rb/resource/page.rb', line 36 def size entities.size end |
- (Object) to_a
59 60 61 |
# File 'lib/coach4rb/resource/page.rb', line 59 def to_a entities end |