Class: TodoGist

Inherits:
Object
  • Object
show all
Defined in:
lib/todo-gist.rb

Overview

A class for managing a to-do list as a Github Gist.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ TodoGist

Returns a new instance of TodoGist.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/todo-gist.rb', line 8

def initialize(username, password)
  @gists = Gists.new(username, password)

  @gist = find_gist()
  if @gist.nil?
    @gist = make_gist()
  end

  # Things is a Ruby array of to-do items that is kept in sync with the Gist
  # contents.
  @things = JSON.parse(@gist["list.json"])
end

Instance Attribute Details

#thingsObject

Returns the value of attribute things.



7
8
9
# File 'lib/todo-gist.rb', line 7

def things
  @things
end

Instance Method Details

#add_thing(thing) ⇒ Object

Does the default adding thing (same as enqueue).



39
40
41
# File 'lib/todo-gist.rb', line 39

def add_thing(thing)
  enqueue(thing)
end

#enqueue(thing) ⇒ Object

Adds an item to the end of the queue.



27
28
29
30
# File 'lib/todo-gist.rb', line 27

def enqueue(thing)
  @things << thing
  update_gist
end

#popObject

Removes the first item from the list.



44
45
46
47
48
# File 'lib/todo-gist.rb', line 44

def pop
  thing = @things.shift
  update_gist
  return thing
end

#push(thing) ⇒ Object

Pushes an item to the front of the queue.



33
34
35
36
# File 'lib/todo-gist.rb', line 33

def push(thing)
  @things.unshift thing
  update_gist
end