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
-
#available ⇒ Object
Returns the value of attribute available.
-
#end ⇒ Object
Returns the value of attribute end.
-
#links ⇒ Object
Returns the value of attribute links.
-
#start ⇒ Object
Returns the value of attribute start.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
- #entities ⇒ Object (also: #items)
- #size ⇒ Object
- #to_a ⇒ Object
Methods included from Mixin::AsHash
Methods included from Mixin::Iterable
Methods included from Mixin::AutoConstructor
Instance Attribute Details
#available ⇒ Object
Returns the value of attribute available.
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def available @available end |
#end ⇒ Object
Returns the value of attribute end.
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def end @end end |
#links ⇒ Object
Returns the value of attribute links.
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def links @links end |
#start ⇒ Object
Returns the value of attribute start.
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def start @start end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def type @type end |
#uri ⇒ Object
Returns the value of attribute uri.
12 13 14 |
# File 'lib/coach4rb/resource/page.rb', line 12 def uri @uri end |
Class Method Details
.from_coach(a_hash, entity_class = Entity) ⇒ Object
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
#[](key) ⇒ Object
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 |
#each(&block) ⇒ Object
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 |
#entities ⇒ Object 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 |
#size ⇒ Object
36 37 38 |
# File 'lib/coach4rb/resource/page.rb', line 36 def size entities.size end |
#to_a ⇒ Object
59 60 61 |
# File 'lib/coach4rb/resource/page.rb', line 59 def to_a entities end |