class TrelloFs::CardBuilder

Attributes

list_builder[R]

Public Class Methods

new(list_builder, card) click to toggle source
# File lib/trello-fs/card_builder.rb, line 9
def initialize(list_builder, card)
  @card = card
  @list_builder = list_builder
end
new_by_card(repository, card) click to toggle source
# 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

Public Instance Methods

attachments_content(attachment_paths = []) click to toggle source
# File lib/trello-fs/card_builder.rb, line 63
def attachments_content(attachment_paths = [])
  return '' unless attachment_paths.any?

  links = attachment_paths.map do |path|
    if is_url?(path)
      name = path
    else
      name = path.split('/').last
      path = "../../#{path}"
    end

    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
board() click to toggle source
# File lib/trello-fs/card_builder.rb, line 105
def board
  board_builder.board
end
board_builder() click to toggle source
# File lib/trello-fs/card_builder.rb, line 101
def board_builder
  @list_builder.board_builder
end
board_name() click to toggle source
# File lib/trello-fs/card_builder.rb, line 109
def board_name
  board_builder.board_name
end
build() click to toggle source
# 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
    if attachment_builder.is_trello_attachment?
      attachment_builder.relative_path
    else
      attachment_builder.url
    end
  end

  File.open(path, 'w') do |file|
    file.write(content(attachment_paths))
  end
end
card_description() click to toggle source
# File lib/trello-fs/card_builder.rb, line 89
def card_description
  LinkReplacer.new(repository).card_description(@card)
end
card_labels() click to toggle source
# File lib/trello-fs/card_builder.rb, line 97
def card_labels
  @card_labels ||= @card.labels
end
card_name() click to toggle source
# File lib/trello-fs/card_builder.rb, line 85
def card_name
  @card.name
end
content(attachment_paths = []) click to toggle source
# File lib/trello-fs/card_builder.rb, line 44
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_name() click to toggle source
# File lib/trello-fs/card_builder.rb, line 40
def file_name
  "#{StringToFileName.convert(@card.name)}.md"
end
list_name() click to toggle source
# File lib/trello-fs/card_builder.rb, line 113
def list_name
  @list_builder.list_name
end
path() click to toggle source
# File lib/trello-fs/card_builder.rb, line 32
def path
  File.join(@list_builder.path, file_name)
end
relative_path() click to toggle source
# File lib/trello-fs/card_builder.rb, line 36
def relative_path
  File.join(@list_builder.relative_path, file_name)
end
repository() click to toggle source
# File lib/trello-fs/card_builder.rb, line 93
def repository
  @list_builder.repository
end
repository_name() click to toggle source
# File lib/trello-fs/card_builder.rb, line 117
def repository_name
  repository.title
end

Private Instance Methods

is_url?(path) click to toggle source
# File lib/trello-fs/card_builder.rb, line 123
def is_url?(path)
  path.start_with?('http://') || path.start_with?('https://')
end