Class: RDoc::Markup::Fragment
- Inherits:
-
Object
- Object
- RDoc::Markup::Fragment
- Defined in:
- lib/rdoc/markup/fragments.rb
Overview
A Fragment is a chunk of text, subclassed as a paragraph, a list entry, or verbatim text.
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
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#txt ⇒ Object
readonly
Returns the value of attribute txt.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #add_text(txt) ⇒ Object
-
#initialize(level, param, type, txt) ⇒ Fragment
constructor
A new instance of Fragment.
- #to_s ⇒ Object
Constructor Details
#initialize(level, param, type, txt) ⇒ Fragment
Returns a new instance of Fragment.
30 31 32 33 34 35 36 |
# File 'lib/rdoc/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
#level ⇒ Object (readonly)
Returns the value of attribute level.
11 12 13 |
# File 'lib/rdoc/markup/fragments.rb', line 11 def level @level end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
11 12 13 |
# File 'lib/rdoc/markup/fragments.rb', line 11 def param @param end |
#txt ⇒ Object (readonly)
Returns the value of attribute txt.
11 12 13 |
# File 'lib/rdoc/markup/fragments.rb', line 11 def txt @txt end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/rdoc/markup/fragments.rb', line 12 def type @type end |
Class Method Details
.for(line) ⇒ Object
24 25 26 27 28 |
# File 'lib/rdoc/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/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/markup/fragments.rb', line 38 def add_text(txt) @txt << " " if @txt.length > 0 @txt << txt.tr_s("\n ", " ").strip end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/rdoc/markup/fragments.rb', line 43 def to_s "L#@level: #{self.class.name.split('::')[-1]}\n#@txt" end |