File: task_list.rb

package info (click to toggle)
ruby-task-list 2.0.0-2~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 248 kB
  • sloc: ruby: 319; sh: 14; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'task_list/summary'
require 'task_list/version'

# encoding: utf-8
class TaskList
  attr_reader :record

  # `record` is the resource with the Markdown source text with task list items
  # following this syntax:
  #
  #   - [ ] a task list item
  #   - [ ] another item
  #   - [x] a completed item
  #
  def initialize(record)
    @record = record
  end

  # Public: return the TaskList::Summary for this task list.
  #
  # Returns a TaskList::Summary.
  def summary
    @summary ||= TaskList::Summary.new(record.task_list_items)
  end

  class Item < Struct.new(:checkbox_text, :source)
    Complete = /\[[xX]\]/.freeze # see TaskList::Filter

    # Public: Check if a task list is complete.
    #
    # Examples
    #
    #   Item.new(checkbox_text: "- [x]").complete?
    #   # => true
    #
    #   Item.new(checkbox_text: "- [ ]").complete?
    #   # => false
    #
    # Returns true for checked list, false otherwise
    def complete?
      !!(checkbox_text =~ Complete)
    end
  end
end