Class: Trello::Board

Inherits:
BasicData show all
Includes:
HasActions
Defined in:
lib/trello/board.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasActions

#actions

Methods inherited from BasicData

#==, #initialize, many, one, #refresh!, register_attributes

Constructor Details

This class inherits a constructor from Trello::BasicData

Class Method Details

.create(fields) ⇒ Object



17
18
19
20
21
# File 'lib/trello/board.rb', line 17

def create(fields)
  new('name'   => fields[:name],
      'desc'   => fields[:description],
      'closed' => fields[:closed] || false).save
end

.find(id) ⇒ Object

Finds a board.



13
14
15
# File 'lib/trello/board.rb', line 13

def find(id)
  super(:boards, id)
end

Instance Method Details

#closed?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/trello/board.rb', line 58

def closed?
  attributes[:closed]
end

#has_lists?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/trello/board.rb', line 62

def has_lists?
  lists.size > 0
end

#request_prefixObject

:nodoc:



91
92
93
# File 'lib/trello/board.rb', line 91

def request_prefix
  "/boards/#{id}"
end

#saveObject



24
25
26
27
28
29
30
31
32
# File 'lib/trello/board.rb', line 24

def save
  return update! if id

  fields = { :name => name }
  fields.merge!(:desc => description) if description
  fields.merge!(:idOrganization => organization_id) if organization_id

  Client.post("/boards", fields).json_into(self)
end

#update!Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/trello/board.rb', line 34

def update!
  fail "Cannot save new instance." unless self.id

  @previously_changed = changes
  @changed_attributes.clear

  Client.put("/boards/#{self.id}/", {
    :name        => @name,
    :description => @description,
    :closed      => @closed
  }).json_into(self)
end

#update_fields(fields) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/trello/board.rb', line 47

def update_fields(fields)
  attributes[:id]              = fields['id']              if fields['id']
  attributes[:name]            = fields['name']            if fields['name']
  attributes[:description]     = fields['desc']            if fields['desc']
  attributes[:closed]          = fields['closed']          if fields.has_key?('closed')
  attributes[:url]             = fields['url']             if fields['url']
  attributes[:organization_id] = fields['idOrganization']  if fields['idOrganization']
  attributes[:prefs]           = fields['prefs'] || {}
  self
end