Class: Ctrl::List

Inherits:
Object
  • Object
show all
Defined in:
lib/ctrl/list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ List

Returns a new instance of List.



5
6
7
8
9
10
11
12
13
# File 'lib/ctrl/list.rb', line 5

def initialize(opts)
  @id = opts["id"]
  @name = opts["name"]
  @position = opts["pos"]
  @closed = opts["closed"]
  @cards = opts["cards"].map { |card| Card.new(card) } if opts["cards"]
  @board = Board.new(opts["board"]) if opts["board"]
  @board_id = opts["idBoard"]
end

Instance Attribute Details

#closedObject

Returns the value of attribute closed.



3
4
5
# File 'lib/ctrl/list.rb', line 3

def closed
  @closed
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ctrl/list.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ctrl/list.rb', line 3

def name
  @name
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/ctrl/list.rb', line 3

def position
  @position
end

Class Method Details

.create(opts) ⇒ Object



17
# File 'lib/ctrl/list.rb', line 17

def self.create(opts); end

.find_all_by_board(board_id) ⇒ Object



39
40
41
# File 'lib/ctrl/list.rb', line 39

def self.find_all_by_board(board_id)
  API.get_lists_for_board(board_id).map{ |list| List.new(list) }
end

.find_by_id(id) ⇒ Object



19
20
21
# File 'lib/ctrl/list.rb', line 19

def self.find_by_id(id)
  List.new(API.get_list(id))
end

.find_by_name(name, board) ⇒ Object



23
24
25
26
# File 'lib/ctrl/list.rb', line 23

def self.find_by_name(name, board)
  fuzzy = FuzzyMatch.new(find_all_by_board(board.id), read: :name)
  fuzzy.find(name)
end

.find_by_position(pos, board) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/ctrl/list.rb', line 28

def self.find_by_position(pos, board)
  pos = 0 if pos == "first" || pos == "top"
  pos = -1 if pos == "last" || pos == "bottom"

  unless pos.is_a? Integer
    fail "Position must by integer, 'top', 'first', 'bottom', or 'last'"
  end

  find_all_by_board(board.id).sort_by(&:position)[pos]
end

Instance Method Details

#boardObject



43
44
45
# File 'lib/ctrl/list.rb', line 43

def board
  @board ||= Board.find_by_id(@board_id)
end

#cardsObject



47
48
49
50
# File 'lib/ctrl/list.rb', line 47

def cards
  return @cards if @cards
  API.get_cards_for_list(id).map { |card| Card.new(card) }
end

#saveObject



15
# File 'lib/ctrl/list.rb', line 15

def save; end