Class: TrelloFs::LabelBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(repository, label) ⇒ LabelBuilder

Returns a new instance of LabelBuilder.



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

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

Instance Method Details

#buildObject



8
9
10
11
12
13
14
# File 'lib/trello-fs/label_builder.rb', line 8

def build
  FileUtils.mkpath(folder_path)

  File.open(path, 'w') do |f|
    f.write content
  end
end


40
41
42
43
44
45
46
47
# File 'lib/trello-fs/label_builder.rb', line 40

def card_links
  @label.cards.sort {|a,b| a.name <=> b.name }.map do |card|
    card_builder = CardBuilder.new_by_card(@repository, card)
    path = '../' + card_builder.relative_path
    link = "[#{card_builder.card_name}](#{path})"
      "- #{link}"
  end.join("\n")
end

#contentObject



32
33
34
35
36
37
38
# File 'lib/trello-fs/label_builder.rb', line 32

def content
  [
    "# `#{label_name}`",
    "[#{@repository.title}](../README.md)",
    card_links
  ].join("\n\n")
end

#file_nameObject



28
29
30
# File 'lib/trello-fs/label_builder.rb', line 28

def file_name
  "#{StringToFileName.convert(label_name)}.md"
end

#folder_pathObject



24
25
26
# File 'lib/trello-fs/label_builder.rb', line 24

def folder_path
  File.join(@repository.path, 'Labels')
end

#label_nameObject



49
50
51
# File 'lib/trello-fs/label_builder.rb', line 49

def label_name
  @label.name.empty? ? 'no name' : @label.name
end

#pathObject



16
17
18
# File 'lib/trello-fs/label_builder.rb', line 16

def path
  File.join(folder_path, file_name)
end

#relative_pathObject



20
21
22
# File 'lib/trello-fs/label_builder.rb', line 20

def relative_path
  File.join('Labels', file_name)
end