Class: TrelloFs::BoardBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/trello-fs/board_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, board) ⇒ BoardBuilder

Returns a new instance of BoardBuilder.



5
6
7
8
# File 'lib/trello-fs/board_builder.rb', line 5

def initialize(repository, board)
  @repository = repository
  @board = board
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



3
4
5
# File 'lib/trello-fs/board_builder.rb', line 3

def board
  @board
end

#repositoryObject (readonly)

Returns the value of attribute repository.



3
4
5
# File 'lib/trello-fs/board_builder.rb', line 3

def repository
  @repository
end

Instance Method Details

#board_nameObject



63
64
65
# File 'lib/trello-fs/board_builder.rb', line 63

def board_name
  @board.name
end

#buildObject



10
11
12
13
14
15
16
# File 'lib/trello-fs/board_builder.rb', line 10

def build
  board.lists.each do |list|
    ListBuilder.new(self, list).build
  end

  build_readme
end

#build_readmeObject



18
19
20
21
22
23
# File 'lib/trello-fs/board_builder.rb', line 18

def build_readme
  readme_path = File.join(path, 'README.md')
  File.open(readme_path, 'w') do |file|
    file.write(readme_content)
  end
end

#folder_nameObject Also known as: relative_path



57
58
59
# File 'lib/trello-fs/board_builder.rb', line 57

def folder_name
  StringToFileName.convert(board_name)
end

#labels_contentObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/trello-fs/board_builder.rb', line 42

def labels_content
  return '' unless @board.labels && @board.labels.any?

  @board.labels.sort {|a, b| a.name <=> b.name }.
    select {|lbl| lbl.cards.any? }.
    map do |label|
    label_builder = LabelBuilder.new(@repository, label)
    "[`#{label_builder.label_name}`](../#{label_builder.relative_path})"
  end.join(' ')
end

#pathObject



53
54
55
# File 'lib/trello-fs/board_builder.rb', line 53

def path
  File.join(@repository.path, folder_name)
end

#readme_contentObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trello-fs/board_builder.rb', line 25

def readme_content
  [
    "# [#{board_name}](#{@board.url})",
    labels_content,
    "[#{repository_name}](../README.md)",
    board.lists.map do |list|
      list_builder = ListBuilder.new(self, list)
      list_link = "[#{list_builder.list_name}](#{list_builder.file_name}/README.md)"

      [
        "## #{list_link}",
        list_builder.content(true)
      ].join("\n\n")
    end.join("\n\n")
  ].join("\n\n")
end

#repository_nameObject



67
68
69
# File 'lib/trello-fs/board_builder.rb', line 67

def repository_name
  @repository.title
end