Class: RDocF95::Markup::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc-f95/markup/fragments.rb

Overview

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

Direct Known Subclasses

Paragraph, Rule, Verbatim

Constant Summary collapse

TYPE_MAP =

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

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, param, type, txt) ⇒ Fragment

Returns a new instance of Fragment.



30
31
32
33
34
35
36
# File 'lib/rdoc-f95/markup/fragments.rb', line 30

def initialize(level, param, type, txt)
  @level = level
  @param = param
  @type  = type
  @txt   = ""
  add_text(txt) if txt
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



11
12
13
# File 'lib/rdoc-f95/markup/fragments.rb', line 11

def level
  @level
end

#paramObject (readonly)

Returns the value of attribute param.



11
12
13
# File 'lib/rdoc-f95/markup/fragments.rb', line 11

def param
  @param
end

#txtObject (readonly)

Returns the value of attribute txt.



11
12
13
# File 'lib/rdoc-f95/markup/fragments.rb', line 11

def txt
  @txt
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/rdoc-f95/markup/fragments.rb', line 12

def type
  @type
end

Class Method Details

.for(line) ⇒ Object



24
25
26
27
28
# File 'lib/rdoc-f95/markup/fragments.rb', line 24

def self.for(line)
  klass =  TYPE_MAP[line.type] ||
    raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'")
  return klass.new(line.level, line.param, line.flag, line.text)
end

.type_name(name) ⇒ Object



20
21
22
# File 'lib/rdoc-f95/markup/fragments.rb', line 20

def self.type_name(name)
  TYPE_MAP[name] = self
end

Instance Method Details

#add_text(txt) ⇒ Object



38
39
40
41
# File 'lib/rdoc-f95/markup/fragments.rb', line 38

def add_text(txt)
  @txt << " " if @txt.length > 0
  @txt << txt.tr_s("\n ", "  ").strip
end

#to_sObject



43
44
45
# File 'lib/rdoc-f95/markup/fragments.rb', line 43

def to_s
  "L#@level: #{self.class.name.split('::')[-1]}\n#@txt"
end