Class: TrelloFs::LinkReplacer
- Inherits:
-
Object
- Object
- TrelloFs::LinkReplacer
- Defined in:
- lib/trello-fs/link_replacer.rb
Instance Method Summary collapse
- #card_description(card) ⇒ Object
-
#initialize(repository) ⇒ LinkReplacer
constructor
A new instance of LinkReplacer.
- #links_in_description(card) ⇒ Object
Constructor Details
#initialize(repository) ⇒ LinkReplacer
Returns a new instance of LinkReplacer.
3 4 5 |
# File 'lib/trello-fs/link_replacer.rb', line 3 def initialize(repository) @repository = repository end |
Instance Method Details
#card_description(card) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/trello-fs/link_replacer.rb', line 7 def card_description(card) links = links_in_description(card) description = card.desc.dup links.each do |link| url = link.first short_link = link.last linked_card = @repository.cards[short_link] next unless linked_card card_builder = CardBuilder.new_by_card(@repository, linked_card) link_to_card = "[#{card_builder.card_name}](../../#{card_builder.relative_path})" description.gsub!(url, link_to_card) end description end |
#links_in_description(card) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/trello-fs/link_replacer.rb', line 26 def links_in_description(card) card.desc.scan(/(https:\/\/trello.com\/c\/[\w]*(?:\/[\w_=+-]*)?)/).map do |match| url = match.first url.match(/https:\/\/trello.com\/c\/([\w]*)/) short_id = $1 [url, short_id] end end |