Class: Tracker
Overview
Track previous posts in ./tmp/articles.json
Constant Summary collapse
- C =
Short cut for Contract
Contracts
Instance Attribute Summary collapse
-
#articles ⇒ Object
Returns the value of attribute articles.
Instance Method Summary collapse
-
#read_articles ⇒ Object
reads articles from the ./tmp/articles.json file.
-
#write_articles ⇒ Object
writes articles from the ./tmp/articles.json file.
Instance Attribute Details
#articles ⇒ Object
Returns the value of attribute articles.
8 9 10 |
# File 'lib/tracker.rb', line 8 def articles @articles end |
Instance Method Details
#read_articles ⇒ Object
reads articles from the ./tmp/articles.json file
15 16 17 18 19 20 21 22 23 |
# File 'lib/tracker.rb', line 15 def read_articles file = JSON.load(File.read("#{Dir.home}/.awl_articles.json")) @articles = file['articles'] rescue JSON::ParserError @articles = [] rescue Errno::ENOENT @articles = [] end |
#write_articles ⇒ Object
writes articles from the ./tmp/articles.json file
27 28 29 30 |
# File 'lib/tracker.rb', line 27 def write_articles f = File.new("#{Dir.home}/.awl_articles.json", 'w') f.write "{ \"articles\": #{@articles} }" end |