Class: Mastodon
- Inherits:
-
Object
- Object
- Mastodon
- Defined in:
- lib/mastodon.rb,
lib/mastodon/todo.rb
Defined Under Namespace
Classes: Todo
Constant Summary
- Context_Regex =
A context is: An at-sign (@) followed by one or more non-whitespace characters.
/(?<!\+)\B@(\S+)/- Project_Regex =
A project is: An plus sign (+) followed by one or more non-whitespace characters.
/(?<!@)\B\+(\S+)/- Priority_Regex =
A priority is: A capital letter (A-Z) surrounded by parentheses, at the beginning of the line.
/^\(([A-Z])\)/
Instance Attribute Summary (collapse)
-
- (Object) contexts
readonly
Returns the value of attribute contexts.
-
- (Object) projects
readonly
Returns the value of attribute projects.
-
- (Object) todos
readonly
Returns the value of attribute todos.
Instance Method Summary (collapse)
-
- (Object) [](id)
Get an individual todo.
-
- (Object) find_context(context)
Find all todos that have the context @context.
-
- (Object) find_project(project)
Find all todos that have the project +project.
-
- (Mastodon) initialize(todos)
constructor
todo: An array of strings (each being an individual todo item).
- - (Object) parse!(todos)
-
- (Object) size
How many todos there are.
Constructor Details
- (Mastodon) initialize(todos)
todo: An array of strings (each being an individual todo item)
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mastodon.rb', line 18 def initialize(todos) @contexts = Set.new @projects = Set.new @todos = [] parse! todos.map{|line| line.strip} @contexts = @contexts.to_a @projects = @projects.to_a end |
Instance Attribute Details
- (Object) contexts (readonly)
Returns the value of attribute contexts
15 16 17 |
# File 'lib/mastodon.rb', line 15 def contexts @contexts end |
- (Object) projects (readonly)
Returns the value of attribute projects
15 16 17 |
# File 'lib/mastodon.rb', line 15 def projects @projects end |
- (Object) todos (readonly)
Returns the value of attribute todos
15 16 17 |
# File 'lib/mastodon.rb', line 15 def todos @todos end |
Instance Method Details
- (Object) [](id)
Get an individual todo. The id and line number are the same. 0 index, not 1, as files are numbered. So line 3 is id 2. XXX: Change?
63 64 65 |
# File 'lib/mastodon.rb', line 63 def [](id) @todos[id] end |
- (Object) find_context(context)
Find all todos that have the context @context
68 69 70 |
# File 'lib/mastodon.rb', line 68 def find_context(context) @todos.select { |todo| todo.contexts.include? context } end |
- (Object) find_project(project)
Find all todos that have the project +project
73 74 75 |
# File 'lib/mastodon.rb', line 73 def find_project(project) @todos.select { |todo| todo.projects.include? project } end |
- (Object) parse!(todos)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mastodon.rb', line 29 def parse!(todos) todos.each do |todo| # Looping through the string, find the metadata (context, project, # priority). Store it in a temporary variable, then clear it from # the original string. Strip all remaining whitespace at the end. current_contexts = [] current_projects = [] current_priority = nil current_contexts = todo.pull_regex(Context_Regex) unless current_contexts.empty? @contexts.merge(current_contexts) end current_projects = todo.pull_regex(Project_Regex) unless current_projects.empty? @projects.merge(current_projects) end current_priority = todo.pull_regex(Priority_Regex) todo.strip! @todos << Mastodon::Todo.new(todo, current_contexts, current_projects, current_priority.first) end end |
- (Object) size
How many todos there are.
57 58 59 |
# File 'lib/mastodon.rb', line 57 def size @todos.size end |