Class: Paragraph

Inherits:
Object show all
Defined in:
lib/tdiary/io/pstore.rb

Overview

Paragraph class

Management a paragraph.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fragment, author = nil) ⇒ Paragraph

Returns a new instance of Paragraph.



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tdiary/io/pstore.rb', line 99

def initialize( fragment, author = nil )
	@author = 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

#bodyObject (readonly) Also known as: body_to_html

Returns the value of attribute body.



95
96
97
# File 'lib/tdiary/io/pstore.rb', line 95

def body
  @body
end

#subtitleObject (readonly) Also known as: subtitle_to_html

Returns the value of attribute subtitle.



95
96
97
# File 'lib/tdiary/io/pstore.rb', line 95

def subtitle
  @subtitle
end

Instance Method Details

#authorObject



126
127
128
129
# File 'lib/tdiary/io/pstore.rb', line 126

def author
	@author = @auther unless @author
	@author
end

#to_sObject



122
123
124
# File 'lib/tdiary/io/pstore.rb', line 122

def to_s
	"subtitle=#{@subtitle}, body=#{@body}"
end

#to_srcObject



112
113
114
115
116
117
118
119
120
# File 'lib/tdiary/io/pstore.rb', line 112

def to_src
	s = ''
	if @subtitle then
		s += "[#{@author}]" if @author
		s += '<' if /^</ =~ @subtitle
		s += @subtitle + "\n"
	end
	"#{s}#{@body}\n\n"
end