Class: Tracker

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/tracker.rb

Overview

Track previous posts in ./tmp/articles.json

Constant Summary collapse

C =

Short cut for Contract

Contracts

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#articlesObject

Returns the value of attribute articles.



8
9
10
# File 'lib/tracker.rb', line 8

def articles
  @articles
end

Instance Method Details

#read_articlesObject

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_articlesObject

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