Class: TrelloFs::ListBuilder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board_builder, list) ⇒ ListBuilder

Returns a new instance of ListBuilder.



9
10
11
12
# File 'lib/trello-fs/list_builder.rb', line 9

def initialize(board_builder, list)
  @board_builder = board_builder
  @list = list
end

Instance Attribute Details

#board_builderObject (readonly)

Returns the value of attribute board_builder.



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

def board_builder
  @board_builder
end

#listObject (readonly)

Returns the value of attribute list.



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

def list
  @list
end

Class Method Details

.new_by_list(repository, list) ⇒ Object



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

def self.new_by_list(repository, list)
  self.new(BoardBuilder.new(repository, list.board), list)
end

Instance Method Details

#board_nameObject



83
84
85
# File 'lib/trello-fs/list_builder.rb', line 83

def board_name
  @board_builder.board_name
end

#buildObject



14
15
16
17
18
19
20
# File 'lib/trello-fs/list_builder.rb', line 14

def build
  list.cards.each do |card|
    CardBuilder.new(self, card).build
  end

  build_readme
end

#build_pathObject



75
76
77
# File 'lib/trello-fs/list_builder.rb', line 75

def build_path
  FileUtils.mkpath(path) unless File.exist? path
end

#build_readmeObject



22
23
24
25
26
27
28
# File 'lib/trello-fs/list_builder.rb', line 22

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

#card_labels(card) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/trello-fs/list_builder.rb', line 51

def card_labels(card)
  labels = card.labels.
    sort {|a, b| a.name <=> b.name }.
    map {|label| "`#{label.name}`" }

  if labels.any?
    ' ' + labels.join(' ')
  else
    ''
  end
end

#content(full_path = false) ⇒ Object



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

def content(full_path = false)
  @list.cards.map do |card|
    cb = CardBuilder.new(self, card)
    card_path = cb.file_name
    card_path = File.join(file_name, card_path) if full_path

    "- [#{cb.card_name}](#{card_path})#{card_labels(card)}"
  end.join("\n")
end

#file_nameObject



71
72
73
# File 'lib/trello-fs/list_builder.rb', line 71

def file_name
  StringToFileName.convert(@list.name)
end

#list_nameObject



79
80
81
# File 'lib/trello-fs/list_builder.rb', line 79

def list_name
  @list.name
end

#pathObject



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

def path
  File.join(@board_builder.path, file_name)
end

#readme_contentObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/trello-fs/list_builder.rb', line 30

def readme_content
  [
    "# #{list_name}",
    [
      "[#{repository_name}](../../README.md)",
      "[#{board_name}](../README.md)"
    ].join(' > '),
    content
  ].join("\n\n")
end

#relative_pathObject



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

def relative_path
  File.join(@board_builder.relative_path, file_name)
end

#repositoryObject



87
88
89
# File 'lib/trello-fs/list_builder.rb', line 87

def repository
  @board_builder.repository
end

#repository_nameObject



91
92
93
# File 'lib/trello-fs/list_builder.rb', line 91

def repository_name
  repository.title
end