Class: SimpleAMS::Adapters::AMS::Collection
- Inherits:
-
SimpleAMS::Adapters::AMS
- Object
- SimpleAMS::Adapters::AMS
- SimpleAMS::Adapters::AMS::Collection
- Defined in:
- lib/simple_ams/adapters/ams.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from SimpleAMS::Adapters::AMS
Instance Method Summary collapse
- #as_json ⇒ Object
- #documents ⇒ Object
-
#initialize(folder, options = {}) ⇒ Collection
constructor
A new instance of Collection.
- #links ⇒ Object
- #metas ⇒ Object
Methods inherited from SimpleAMS::Adapters::AMS
Constructor Details
#initialize(folder, options = {}) ⇒ Collection
Returns a new instance of Collection.
74 75 76 77 78 |
# File 'lib/simple_ams/adapters/ams.rb', line 74 def initialize(folder, = {}) @folder = folder @adapter = folder.adapter.value @options = end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
72 73 74 |
# File 'lib/simple_ams/adapters/ams.rb', line 72 def adapter @adapter end |
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
72 73 74 |
# File 'lib/simple_ams/adapters/ams.rb', line 72 def folder @folder end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
72 73 74 |
# File 'lib/simple_ams/adapters/ams.rb', line 72 def @options end |
Instance Method Details
#as_json ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/simple_ams/adapters/ams.rb', line 80 def as_json if [:root] { folder.name => documents, meta: , links: links } else documents end end |
#documents ⇒ Object
92 93 94 95 96 |
# File 'lib/simple_ams/adapters/ams.rb', line 92 def documents return folder.map{|document| adapter.new(document).as_json } || [] end |
#links ⇒ Object
105 106 107 108 109 110 |
# File 'lib/simple_ams/adapters/ams.rb', line 105 def links @links ||= folder.links.inject({}){ |hash, link| hash[link.name] = link.value hash } end |
#metas ⇒ Object
98 99 100 101 102 103 |
# File 'lib/simple_ams/adapters/ams.rb', line 98 def @metas ||= folder..inject({}){ |hash, | hash[.name] = .value hash } end |