class TrelloFs::AttachmentBuilder
Attributes
attachment[R]
card_builder[R]
Public Class Methods
new(card_builder, attachment)
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 11 def initialize(card_builder, attachment) @card_builder = card_builder @attachment = attachment end
new_by_attachment(repository, attachment)
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 7 def self.new_by_attachment(repository, attachment) self.new(CardBuilder.new_by_card(repository, attachment.card), attachment) end
Public Instance Methods
already_downloaded?()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 54 def already_downloaded? File.exist? path end
board_builder()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 70 def board_builder @card_builder.board_builder end
build()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 16 def build return if already_downloaded? download_and_save end
download()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 62 def download open(url).read end
download_and_save()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 22 def download_and_save return unless is_trello_attachment? data = download return unless data FileUtils.mkpath(full_folder_path) unless File.exist? full_folder_path File.open(path, 'wb') do |file| file.write data end end
file_name()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 50 def file_name @attachment.name.gsub(/[()\[\], ]/, '-') end
folder_path()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 42 def folder_path File.join('Attachments', board_builder.folder_name, StringToFileName.convert(@card_builder.card_name)) end
full_folder_path()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 46 def full_folder_path File.join(repository.path, folder_path) end
is_trello_attachment?()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 58 def is_trello_attachment? url.include?('trello-attachments.s3.amazonaws.com') end
path()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 34 def path File.join(full_folder_path, file_name) end
relative_path()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 38 def relative_path File.join(folder_path, file_name) end
repository()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 66 def repository @card_builder.repository end
url()
click to toggle source
# File lib/trello-fs/attachment_builder.rb, line 74 def url @attachment.url end