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
- #card_structure ⇒ 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 48 49 50 51 52 53 |
# File 'lib/trello-fs/label_builder.rb', line 40 def card_links card_structure.sort.map do |board_path, lists| list_paths = lists.sort.map do |list_path, cards| card_paths = cards.sort.map do |card_path| "- #{card_path}" end.join("\n") "## #{list_path}\n\n#{card_paths}" end.join("\n\n") "# #{board_path}\n\n#{list_paths}" end.join("\n\n") # links.sort {|a,b| a <=> b }.join("\n") end |
#card_structure ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/trello-fs/label_builder.rb', line 55 def card_structure structure = {} @label.cards.map do |card| card_builder = CardBuilder.new_by_card(@repository, card) board_builder = card_builder.board_builder list_builder = card_builder.list_builder board_path = "[#{board_builder.board_name}](../#{board_builder.relative_path}/README.md)" list_path = "[#{list_builder.list_name}](../#{list_builder.relative_path}/README.md)" card_path = "[#{card_builder.card_name}](../#{card_builder.relative_path})" ((structure[board_path] ||= {})[list_path] ||= []) << card_path end structure 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
73 74 75 |
# File 'lib/trello-fs/label_builder.rb', line 73 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 |