Sha256: 71621d68c64f06544c9a58cc0dbc7bec191e4ea49fb15212e6e63d39472b26bd

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

module Things
  class List < Reference::Base
    
    DEFAULTS = [:inbox, :today, :next, :scheduled, :someday, :projects, :logbook, :trash]
    
    def todos
      Things::Todo.convert(reference.todos.get)
    end
    
    class << self
      
      # Returns an Appscript Reference to the entire collection of todos
      def reference
        Things::App.instance.lists
      end

      # Converts a collection of reference into a collection of objects
      def convert(references)
        references = [references] if !references.is_a?(Array)
        references.collect { |todo| build(todo) }
      end
      
      def all
        convert(reference.get)
      end
      
      # build a new instance and link it to the supplied reference
      #
      # Returns a object associated with a reference
      def build(reference)
        todo = self.new
        todo.reference = reference
        todo
      end

      DEFAULTS.each do |list|
        class_eval <<-"eval"
          def #{list}
            convert(reference['#{list.to_s.capitalize}'].get).first
          end
        eval
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
things-client-0.2.4 lib/things/list.rb
things-client-0.2.3 lib/things/list.rb
things-client-0.2.2 lib/things/list.rb
things-client-0.2.1 lib/things/list.rb
things-client-0.2.0 lib/things/list.rb