Method: Lhj::TbHelper.trans_tb

Defined in:
lib/lhj/helper/tb_helper.rb

.trans_tb(note) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lhj/helper/tb_helper.rb', line 13

def self.trans_tb(note)
  str = note
  if /#.+#/ =~ note
    note.scan(/#[^#]+#/) do |m|
      rec_reg = m.match(/rec\w+/)
      next if rec_reg

      ma = m.match(/\d+/)
      next if !ma || !ma[0] || ma[0].length <= 0

      res_body = req_with_task(ma[0])
      if res_body && res_body['code'].to_i == 200
        url_str = "[#{res_body['result'][0]['content']}](https://www.teambition.com/task/#{res_body['result'][0]['taskId']})"
        str = str.gsub(m, url_str)
      end
    end
  end
  str
end