Class: TrelloFs::CardBuilder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_builder, card) ⇒ CardBuilder

Returns a new instance of CardBuilder.



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

def initialize(list_builder, card)
  @card = card
  @list_builder = list_builder
end

Instance Attribute Details

#list_builderObject (readonly)

Returns the value of attribute list_builder.



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

def list_builder
  @list_builder
end

Class Method Details

.new_by_card(repository, card) ⇒ Object



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

def self.new_by_card(repository, card)
  self.new(ListBuilder.new_by_list(repository, card.list), card)
end

Instance Method Details

#attachments_content(attachment_paths = []) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/trello-fs/card_builder.rb', line 59

def attachments_content(attachment_paths = [])
  return '' unless attachment_paths.any?

  links = attachment_paths.map do |path|
    name = path.split('/').last
    path = "../../#{path}"
    link = "[#{name}](#{path})"
    if path.end_with?('.png') || path.end_with?('.jpg') || path.end_with?('gif') || path.end_with?('.jpeg')
      "!#{link}"
    else
      link
    end
  end.join("\n\n")

  "\n\n## Attachments\n\n#{links}"
end

#boardObject



96
97
98
# File 'lib/trello-fs/card_builder.rb', line 96

def board
  board_builder.board
end

#board_builderObject



92
93
94
# File 'lib/trello-fs/card_builder.rb', line 92

def board_builder
  @list_builder.board_builder
end

#board_nameObject



100
101
102
# File 'lib/trello-fs/card_builder.rb', line 100

def board_name
  board_builder.board_name
end

#buildObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/trello-fs/card_builder.rb', line 14

def build
  @list_builder.build_path

  attachment_paths = @card.attachments.map do |attachment|
    attachment_builder = AttachmentBuilder.new(self, attachment)
    attachment_builder.build
    attachment_builder.relative_path
  end

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

#card_descriptionObject



80
81
82
# File 'lib/trello-fs/card_builder.rb', line 80

def card_description
  LinkReplacer.new(repository).card_description(@card)
end

#card_labelsObject



88
89
90
# File 'lib/trello-fs/card_builder.rb', line 88

def card_labels
  @card_labels ||= @card.labels
end

#card_nameObject



76
77
78
# File 'lib/trello-fs/card_builder.rb', line 76

def card_name
  @card.name
end

#content(attachment_paths = []) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/trello-fs/card_builder.rb', line 40

def content(attachment_paths = [])
  labels = card_labels.map do |lbl|
    label_builder = LabelBuilder.new(repository, lbl)
    "[`#{label_builder.label_name}`](../../#{label_builder.relative_path})"
  end.sort.join(' ')

  [
    "# [#{card_name}](#{@card.url})",
    [
      "[#{repository_name}](../../README.md)",
      "[#{board_name}](../README.md)",
      "[#{list_name}](README.md)"
    ].join(' > '),
    labels,
    card_description,
    attachments_content(attachment_paths)
  ].join("\n\n")
end

#file_nameObject



36
37
38
# File 'lib/trello-fs/card_builder.rb', line 36

def file_name
  "#{StringToFileName.convert(@card.name)}.md"
end

#list_nameObject



104
105
106
# File 'lib/trello-fs/card_builder.rb', line 104

def list_name
  @list_builder.list_name
end

#pathObject



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

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

#relative_pathObject



32
33
34
# File 'lib/trello-fs/card_builder.rb', line 32

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

#repositoryObject



84
85
86
# File 'lib/trello-fs/card_builder.rb', line 84

def repository
  @list_builder.repository
end

#repository_nameObject



108
109
110
# File 'lib/trello-fs/card_builder.rb', line 108

def repository_name
  repository.title
end