Class: TodoReaderJSON
- Inherits:
-
Object
- Object
- TodoReaderJSON
- Includes:
- TodoReaderInterface
- Defined in:
- lib/todo_analyser/todo_reader_json.rb
Overview
Concrete implementation for JSON TODOs
Instance Method Summary collapse
-
#initialize(todo_path) ⇒ TodoReaderJSON
constructor
A new instance of TodoReaderJSON.
- #read_todos ⇒ Object
Constructor Details
#initialize(todo_path) ⇒ TodoReaderJSON
Returns a new instance of TodoReaderJSON.
13 14 15 |
# File 'lib/todo_analyser/todo_reader_json.rb', line 13 def initialize(todo_path) @todo_path = todo_path end |
Instance Method Details
#read_todos ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/todo_analyser/todo_reader_json.rb', line 17 def read_todos uri = URI(@todo_path) todos_string = Net::HTTP.get(uri) todos = JSON.parse todos_string todos.each_with_index do |todo, i| next unless i.odd? # Check for even lines title = todo['title'] completed = todo['completed'] yield Todo.new(title.strip, completed.to_s.strip.downcase == 'true') end end |