Sha256: ae7e490e7497fe7b45469185c46d2f37cb3d7ff3d1380db1491d7860ee221f18

Contents?: true

Size: 975 Bytes

Versions: 8

Compression:

Stored size: 975 Bytes

Contents

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("- [x]").complete?
    #   # => true
    #
    #   Item.new("- [ ]").complete?
    #   # => false
    #
    # Returns true for checked list, false otherwise
    def complete?
      !!(checkbox_text =~ Complete)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
deckar01-task_list-2.3.4 lib/task_list.rb
deckar01-task_list-2.3.3 lib/task_list.rb
deckar01-task_list-3.0.alpha2 lib/task_list.rb
deckar01-task_list-3.0.alpha1 lib/task_list.rb
deckar01-task_list-2.3.2 lib/task_list.rb
deckar01-task_list-2.3.1 lib/task_list.rb
deckar01-task_list-2.3.0 lib/task_list.rb
deckar01-task_list-2.2.1 lib/task_list.rb