Class: TrelloFs::AttachmentBuilder
- Inherits:
-
Object
- Object
- TrelloFs::AttachmentBuilder
- Defined in:
- lib/trello-fs/attachment_builder.rb
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
-
#card_builder ⇒ Object
readonly
Returns the value of attribute card_builder.
Class Method Summary collapse
Instance Method Summary collapse
- #already_downloaded? ⇒ Boolean
- #board_builder ⇒ Object
- #build ⇒ Object
- #download ⇒ Object
- #download_and_save ⇒ Object
- #file_name ⇒ Object
- #folder_path ⇒ Object
- #full_folder_path ⇒ Object
-
#initialize(card_builder, attachment) ⇒ AttachmentBuilder
constructor
A new instance of AttachmentBuilder.
- #path ⇒ Object
- #relative_path ⇒ Object
- #repository ⇒ Object
Constructor Details
#initialize(card_builder, attachment) ⇒ AttachmentBuilder
Returns a new instance of AttachmentBuilder.
11 12 13 14 |
# File 'lib/trello-fs/attachment_builder.rb', line 11 def initialize(card_builder, ) @card_builder = card_builder = end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
5 6 7 |
# File 'lib/trello-fs/attachment_builder.rb', line 5 def end |
#card_builder ⇒ Object (readonly)
Returns the value of attribute card_builder.
5 6 7 |
# File 'lib/trello-fs/attachment_builder.rb', line 5 def card_builder @card_builder end |
Class Method Details
.new_by_attachment(repository, attachment) ⇒ Object
7 8 9 |
# File 'lib/trello-fs/attachment_builder.rb', line 7 def self.(repository, ) self.new(CardBuilder.new_by_card(repository, .card), ) end |
Instance Method Details
#already_downloaded? ⇒ Boolean
52 53 54 |
# File 'lib/trello-fs/attachment_builder.rb', line 52 def already_downloaded? File.exist? path end |
#board_builder ⇒ Object
64 65 66 |
# File 'lib/trello-fs/attachment_builder.rb', line 64 def board_builder @card_builder.board_builder end |
#build ⇒ Object
16 17 18 19 20 |
# File 'lib/trello-fs/attachment_builder.rb', line 16 def build return if already_downloaded? download_and_save end |
#download ⇒ Object
56 57 58 |
# File 'lib/trello-fs/attachment_builder.rb', line 56 def download open(.url).read end |
#download_and_save ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/trello-fs/attachment_builder.rb', line 22 def download_and_save 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 ⇒ Object
48 49 50 |
# File 'lib/trello-fs/attachment_builder.rb', line 48 def file_name .name.gsub(/ /, '_') end |
#folder_path ⇒ Object
40 41 42 |
# File 'lib/trello-fs/attachment_builder.rb', line 40 def folder_path File.join('Attachments', board_builder.folder_name, StringToFileName.convert(@card_builder.card_name)) end |
#full_folder_path ⇒ Object
44 45 46 |
# File 'lib/trello-fs/attachment_builder.rb', line 44 def full_folder_path File.join(repository.path, folder_path) end |
#path ⇒ Object
32 33 34 |
# File 'lib/trello-fs/attachment_builder.rb', line 32 def path File.join(full_folder_path, file_name) end |
#relative_path ⇒ Object
36 37 38 |
# File 'lib/trello-fs/attachment_builder.rb', line 36 def relative_path File.join(folder_path, file_name) end |
#repository ⇒ Object
60 61 62 |
# File 'lib/trello-fs/attachment_builder.rb', line 60 def repository @card_builder.repository end |