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, #serialize, subclasses, try, #type, type

Constructor Details

#initialize(string) ⇒ Markdown


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

def initialize(string)
  @string = string
end

Class Method Details

.new(item) ⇒ Object


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

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

.parse(string) ⇒ Object


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

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

Instance Method Details

#==(other) ⇒ Object


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

def ==(other)
  to_s == other.to_s
end

#to_nativeObject


40
41
42
# File 'lib/saper/items/markdown.rb', line 40

def to_native
  @string
end

#to_sObject


35
36
37
# File 'lib/saper/items/markdown.rb', line 35

def to_s
  to_native
end