Sha256: 713c0c600a982edcccdb8222c6bf63c6ef71178da2b6ceef4614f250d7bb4768

Contents?: true

Size: 626 Bytes

Versions: 4

Compression:

Stored size: 626 Bytes

Contents

module TaskManager
  class NewTaskFile < TaskFile
    def pick(id)
      node = root_node.css('task').find { |t| t['id'].to_i == id.to_i }
      raise 'ID not exists'.colorize(:light_red) unless node
      task = Task.new_from_node(node)
      handle_xml { node.remove }
      task
    end

    protected

    def root_node
      @root_node ||= begin
        xml.css(NEW_NODE).first || begin
          node = xml.create_element(NEW_NODE)
          super.add_child(node)
          node
        end
      end
    end

    def create_node(task)
      node = super
      node['created_at'] = time_now
      node
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
task_manager2-0.0.11 lib/task_manager/new_task_file.rb
task_manager2-0.0.10 lib/task_manager/new_task_file.rb
task_manager2-0.0.9 lib/task_manager/new_task_file.rb
task_manager2-0.0.8 lib/task_manager/new_task_file.rb