Class: NewsStand::Memory
- Inherits:
-
Object
- Object
- NewsStand::Memory
- Defined in:
- lib/news_stand/memory.rb
Class Method Summary collapse
- .all ⇒ Object
- .get(key) ⇒ Object
- .issues ⇒ Object
- .next_key ⇒ Object
- .reset ⇒ Object
- .set(attributes) ⇒ Object
Instance Method Summary collapse
- #all ⇒ Object
- #get(number) ⇒ Object
-
#initialize(options = {}) ⇒ Memory
constructor
A new instance of Memory.
- #set(attributes = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Memory
Returns a new instance of Memory.
5 6 7 |
# File 'lib/news_stand/memory.rb', line 5 def initialize( = {}) = end |
Class Method Details
.all ⇒ Object
26 27 28 |
# File 'lib/news_stand/memory.rb', line 26 def all issues.values end |
.get(key) ⇒ Object
30 31 32 |
# File 'lib/news_stand/memory.rb', line 30 def get(key) issues[key] end |
.issues ⇒ Object
22 23 24 |
# File 'lib/news_stand/memory.rb', line 22 def issues @issues ||= {} end |
.next_key ⇒ Object
39 40 41 |
# File 'lib/news_stand/memory.rb', line 39 def next_key issues.keys.length + 1 end |
.reset ⇒ Object
43 44 45 |
# File 'lib/news_stand/memory.rb', line 43 def reset issues.clear end |
.set(attributes) ⇒ Object
34 35 36 37 |
# File 'lib/news_stand/memory.rb', line 34 def set(attributes) key = (attributes['number'] ||= next_key) issues[key] = attributes end |
Instance Method Details
#all ⇒ Object
9 10 11 |
# File 'lib/news_stand/memory.rb', line 9 def all self.class.all end |
#get(number) ⇒ Object
13 14 15 |
# File 'lib/news_stand/memory.rb', line 13 def get(number) self.class.get(number) end |
#set(attributes = {}) ⇒ Object
17 18 19 |
# File 'lib/news_stand/memory.rb', line 17 def set(attributes = {}) self.class.set(attributes) end |