Class SM::Fragment
In: markup/simple_markup/fragments.rb
Parent: Object

A Fragment is a chunk of text, subclassed as a paragraph, a list entry, or verbatim text

Methods

add_text   for   new   to_s   type_name  

Constants

TYPE_MAP = {}   This is a simple factory system that lets us associate fragement types (a string) with a subclass of fragment

Attributes

level  [R] 
param  [R] 
txt  [R] 
type  [RW] 

Public Class methods

[Source]

    # File markup/simple_markup/fragments.rb, line 41
41:     def Fragment.for(line)
42:       klass =  TYPE_MAP[line.type] ||
43:         raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'")
44:       return klass.new(line.level, line.param, line.flag, line.text)
45:     end

[Source]

    # File markup/simple_markup/fragments.rb, line 14
14:     def initialize(level, param, type, txt)
15:       @level = level
16:       @param = param
17:       @type  = type
18:       @txt   = ""
19:       add_text(txt) if txt
20:     end

[Source]

    # File markup/simple_markup/fragments.rb, line 37
37:     def Fragment.type_name(name)
38:       TYPE_MAP[name] = self
39:     end

Public Instance methods

[Source]

    # File markup/simple_markup/fragments.rb, line 22
22:     def add_text(txt)
23:       @txt << " " if @txt.length > 0
24:       @txt << txt.tr_s("\n ", "  ").strip
25:     end

[Source]

    # File markup/simple_markup/fragments.rb, line 27
27:     def to_s
28:       "L#@level: #{self.class.name.split('::')[-1]}\n#@txt"
29:     end

[Validate]