Class: Paragraph
- Inherits:
-
Object
- Object
- Paragraph
- Defined in:
- lib/tdiary/io/pstore.rb
Overview
Paragraph class
Management a paragraph.
Instance Attribute Summary collapse
-
#body ⇒ Object
(also: #body_to_html)
readonly
Returns the value of attribute body.
-
#subtitle ⇒ Object
(also: #subtitle_to_html)
readonly
Returns the value of attribute subtitle.
Instance Method Summary collapse
- #author ⇒ Object
-
#initialize(fragment, author = nil) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #to_s ⇒ Object
- #to_src ⇒ Object
Constructor Details
#initialize(fragment, author = nil) ⇒ Paragraph
Returns a new instance of Paragraph.
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/tdiary/io/pstore.rb', line 98 def initialize( fragment, = nil ) @author = lines = fragment.split( /\n+/ ) if lines.size > 1 then if /^<</ =~ lines[0] @subtitle = lines.shift.chomp.sub( /^</, '' ) elsif /^[ <]/u !~ lines[0] @subtitle = lines.shift.chomp end end @body = lines.join( "\n" ) end |
Instance Attribute Details
#body ⇒ Object (readonly) Also known as: body_to_html
Returns the value of attribute body.
94 95 96 |
# File 'lib/tdiary/io/pstore.rb', line 94 def body @body end |
#subtitle ⇒ Object (readonly) Also known as: subtitle_to_html
Returns the value of attribute subtitle.
94 95 96 |
# File 'lib/tdiary/io/pstore.rb', line 94 def subtitle @subtitle end |
Instance Method Details
#author ⇒ Object
125 126 127 128 |
# File 'lib/tdiary/io/pstore.rb', line 125 def @author = @auther unless @author @author end |
#to_s ⇒ Object
121 122 123 |
# File 'lib/tdiary/io/pstore.rb', line 121 def to_s "subtitle=#{@subtitle}, body=#{@body}" end |
#to_src ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/tdiary/io/pstore.rb', line 111 def to_src s = '' if @subtitle then s += "[#{@author}]" if @author s += '<' if /^</ =~ @subtitle s += @subtitle + "\n" end "#{s}#{@body}\n\n" end |