class Kanboard::Board

Attributes

all_cards[RW]
project[RW]
statuses[RW]
swimlanes[RW]

Public Class Methods

new() click to toggle source
# File lib/kanboard/board.rb, line 25
def initialize
  @project = ""
  @statuses = []         # all statuses (h2. strings) defined in the input file
  @swimlanes = []        # all unique swim-lane (+ strings) defined in the input file
  @cards = Hash.new      # cards organised by board position
  @all_cards = Array.new # all cards defined in the input file
end

Public Instance Methods

cards(status, swimlane) click to toggle source
# File lib/kanboard/board.rb, line 68
def cards(status, swimlane)
  @cards[hash(status, swimlane)] || Array.new  # so that we always return an array
end
cards_of(owner) click to toggle source

return all the cards owned by owner

# File lib/kanboard/board.rb, line 82
def cards_of(owner)
  @all_cards.select { |c| c.owner == owner }
end
load(filename) click to toggle source
# File lib/kanboard/board.rb, line 33
def load filename
  current_status = "" # current status

  File.open(filename).each do |line|
    # set the title to the first h1 found in the file
    match = line.match(/^h1\.[ ]+(.+)$/)
    if match and @project == ""
      @project = match[1]
    end

    # look for statuses and add them to the list of statuses.
    # don't bother about duplications
    match = line.match(/^h2\.[ ]+(.+)$/)
    if match
      @statuses << match[1]
      current_status = match[1]
    end

    # look for cards and manage them
    if line.start_with?('- ') # make sure we ignore YAML front matter ("---")
      card = Kanboard::Card.new(@project, @status, line)
      swimlane = card.swimlane
      owner = card.owner

      @swimlanes << swimlane unless @swimlanes.include? swimlane

      position = hash(current_status, swimlane)
      @cards[position] = Array.new unless @cards[position]
      @cards[position] << card

      @all_cards << card
    end
  end
end
owners() click to toggle source

return all the owners mentioned in the input file

# File lib/kanboard/board.rb, line 75
def owners
  @all_cards.map { |c| c.owner }.uniq
end

Private Instance Methods

hash(status, swimlane) click to toggle source

generate an hash which uniquely identifies a cell in the kanban board

# File lib/kanboard/board.rb, line 91
def hash(status, swimlane)
  status + "*" + swimlane
end