Class: TrelloFs::LabelBuilder
- Inherits:
-
Object
- Object
- TrelloFs::LabelBuilder
- Defined in:
- lib/trello-fs/label_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #card_links ⇒ Object
- #content ⇒ Object
- #file_name ⇒ Object
- #folder_path ⇒ Object
-
#initialize(repository, label) ⇒ LabelBuilder
constructor
A new instance of LabelBuilder.
- #label_name ⇒ Object
- #path ⇒ Object
- #relative_path ⇒ Object
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
#build ⇒ Object
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 |
#card_links ⇒ Object
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 |
#content ⇒ Object
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_name ⇒ Object
28 29 30 |
# File 'lib/trello-fs/label_builder.rb', line 28 def file_name "#{StringToFileName.convert(label_name)}.md" end |
#folder_path ⇒ Object
24 25 26 |
# File 'lib/trello-fs/label_builder.rb', line 24 def folder_path File.join(@repository.path, 'Labels') end |
#label_name ⇒ Object
49 50 51 |
# File 'lib/trello-fs/label_builder.rb', line 49 def label_name @label.name.empty? ? 'no name' : @label.name end |
#path ⇒ Object
16 17 18 |
# File 'lib/trello-fs/label_builder.rb', line 16 def path File.join(folder_path, file_name) end |
#relative_path ⇒ Object
20 21 22 |
# File 'lib/trello-fs/label_builder.rb', line 20 def relative_path File.join('Labels', file_name) end |