Class: Contraption::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/contraption/post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object (private)



49
50
51
# File 'lib/contraption/post.rb', line 49

def method_missing m, *a, &b
  .public_send(m, *a, &b)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



42
43
44
# File 'lib/contraption/post.rb', line 42

def body
  @body
end

#metadataObject (readonly)

Returns the value of attribute metadata.



42
43
44
# File 'lib/contraption/post.rb', line 42

def 
  
end

Class Method Details

.build(data = "") ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/contraption/post.rb', line 8

def build data=""
  data = data.to_s

  splitted = data.split(/\n\n/, 2)
  Post.new Header.from(splitted.first), translate_markdown(splitted.last)
rescue ArgumentError => e
  Post.new Header.from(""), ""
end

.translate_markdown(content) ⇒ Object



17
18
19
# File 'lib/contraption/post.rb', line 17

def translate_markdown content
  Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content)
end

Instance Method Details

#publish(link_handlers = []) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/contraption/post.rb', line 22

def publish link_handlers=[]
  links = list_links

  links.map! do |link|
    h = link_handlers.select{|l| l.protocol == link.first.to_sym}
    if h.length > 1
      raise "Multiple link handlers for #{link.first} protocol"
    elsif h.length == 0
      nil
    else
      h = h.first
      [link, h.handle(link)]
    end
  end.compact!

  update_links links

  Post.new( .update({publication_date: Time.now}), body)
end