Class: Trahald::MarkdownBody

Inherits:
Object
  • Object
show all
Defined in:
lib/trahald/markdown-body.rb

Defined Under Namespace

Classes: Summary

Constant Summary collapse

MAX_TEXT_SIZE =
160

Instance Method Summary collapse

Constructor Details

#initialize(name, body, date) ⇒ MarkdownBody

Returns a new instance of MarkdownBody.



11
12
13
14
15
# File 'lib/trahald/markdown-body.rb', line 11

def initialize(name, body, date)
  @name = name
  @body = body
  @date = date
end

Instance Method Details

#img_srcObject



26
27
28
29
30
31
32
# File 'lib/trahald/markdown-body.rb', line 26

def img_src
  pattern = Regexp.new '!\[.+\]\((.+)\)'
  raw = @body.split('\n')
  raw.map{|r|
    $1 if pattern =~ r
  }.select{|i| i}
end

#preObject



17
18
19
20
21
22
23
24
# File 'lib/trahald/markdown-body.rb', line 17

def pre 
  raw = Sanitize.clean Kramdown::Document.new(@body).to_html
  if raw.size > MAX_TEXT_SIZE 
    raw[0, MAX_TEXT_SIZE] + "..."
  else
    raw
  end
end

#summaryObject



34
35
36
37
38
39
40
41
# File 'lib/trahald/markdown-body.rb', line 34

def summary
  Summary.new(
    @name,
    img_src,
    pre,
    @date
  )
end