Class: Saper::Items::Markdown

Inherits:
Saper::Item show all
Defined in:
lib/saper/items/markdown.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Saper::Item

#==, [], exists?, inherited, subclasses, try, type, #type

Constructor Details

#initialize(string) ⇒ Markdown

Returns a new instance of Markdown.



22
23
24
# File 'lib/saper/items/markdown.rb', line 22

def initialize(string)
  @string = string
end

Class Method Details

.new(item) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/saper/items/markdown.rb', line 5

def self.new(item)
  super case item
  when HTML
    parse(item.inner_html)
  else
    raise(InvalidItem, item)
  end
end

.parse(string) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/saper/items/markdown.rb', line 14

def self.parse(string)
  begin
    ::ReverseMarkdown.convert(string).strip
  rescue
    raise(InvalidItem, string)
  end
end

Instance Method Details

#to_nativeObject



30
31
32
# File 'lib/saper/items/markdown.rb', line 30

def to_native
  to_s
end

#to_sObject



26
27
28
# File 'lib/saper/items/markdown.rb', line 26

def to_s
  @string
end