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.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tdiary/io/pstore.rb', line 101 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.
97 98 99 |
# File 'lib/tdiary/io/pstore.rb', line 97 def body @body end |
#subtitle ⇒ Object (readonly) Also known as: subtitle_to_html
Returns the value of attribute subtitle.
97 98 99 |
# File 'lib/tdiary/io/pstore.rb', line 97 def subtitle @subtitle end |
Instance Method Details
#author ⇒ Object
128 129 130 131 |
# File 'lib/tdiary/io/pstore.rb', line 128 def @author = @auther unless @author @author end |
#to_s ⇒ Object
124 125 126 |
# File 'lib/tdiary/io/pstore.rb', line 124 def to_s "subtitle=#{@subtitle}, body=#{@body}" end |
#to_src ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/tdiary/io/pstore.rb', line 114 def to_src s = '' if @subtitle then s += "[#{@author}]" if @author s += '<' if /^</ =~ @subtitle s += @subtitle + "\n" end "#{s}#{@body}\n\n" end |