Class: Diary
- Inherits:
-
Object
- Object
- Diary
- Includes:
- TDiary::BaseDiary, TDiary::UncategorizableDiary
- Defined in:
- lib/tdiary/io/pstore.rb
Overview
Diary class
Management a day of diary
Instance Method Summary collapse
- #append(body, author = nil) ⇒ Object
- #each_section ⇒ Object
-
#initialize(date, title, body) ⇒ Diary
constructor
A new instance of Diary.
- #replace(date, title, body) ⇒ Object
- #style ⇒ Object
- #to_chtml(opt) ⇒ Object
- #to_html(opt, mode = :HTML) ⇒ Object
- #to_html4(opt) ⇒ Object
- #to_s ⇒ Object
- #to_src ⇒ Object
Constructor Details
#initialize(date, title, body) ⇒ Diary
Returns a new instance of Diary.
142 143 144 145 |
# File 'lib/tdiary/io/pstore.rb', line 142 def initialize( date, title, body ) init_diary replace( date, title, body ) end |
Instance Method Details
#append(body, author = nil) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/tdiary/io/pstore.rb', line 158 def append( body, = nil ) body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment| paragraph = Paragraph::new( fragment, ) @paragraphs << paragraph if paragraph end @last_modified = Time::now self end |
#each_section ⇒ Object
167 168 169 170 171 |
# File 'lib/tdiary/io/pstore.rb', line 167 def each_section @paragraphs.each do |paragraph| yield paragraph end end |
#replace(date, title, body) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/tdiary/io/pstore.rb', line 151 def replace( date, title, body ) set_date( date ) set_title( title ) @paragraphs = [] append( body ) end |
#style ⇒ Object
147 148 149 |
# File 'lib/tdiary/io/pstore.rb', line 147 def style 'tDiary' end |
#to_chtml(opt) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/tdiary/io/pstore.rb', line 223 def to_chtml( opt ) idx = 0 r = '' each_section do |paragraph| if paragraph.subtitle then r << %Q[<P><A NAME="p#{'%02d' % idx += 1}">*</A> #{paragraph.subtitle}</P>] end if /^</ =~ paragraph.body then idx += 1 r << paragraph.body elsif paragraph.subtitle r << %Q[<P>#{paragraph.body.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</P>\n<P>" )}</P>] else r << %Q[<P><A NAME="p#{'%02d' % idx += 1}">*</A> ] if opt['multi_user'] and paragraph. then r << %Q|[#{paragraph.}]| end r << %Q[#{paragraph.body.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</P>\n<P>" )}</P>] end end r end |
#to_html(opt, mode = :HTML) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/tdiary/io/pstore.rb', line 181 def to_html( opt, mode = :HTML ) case mode when :CHTML to_chtml( opt ) else to_html4( opt ) end end |
#to_html4(opt) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/tdiary/io/pstore.rb', line 190 def to_html4( opt ) idx = 1 r = '' each_section do |paragraph| r << %Q[<div class="section">\n] if paragraph.subtitle then r << %Q[<h3><a ] if opt['anchor'] then r << %Q[name="p#{'%02d' % idx}" ] end r << %Q[href="#{opt['index']}<%=anchor "#{@date.strftime( '%Y%m%d' )}#p#{'%02d' % idx}" %>">#{opt['section_anchor']}</a> ] if opt['multi_user'] and paragraph. then r << %Q|[#{paragraph.}]| end r << %Q[#{paragraph.subtitle}</h3>] end if /^</ =~ paragraph.body then r << %Q[#{paragraph.body}] elsif paragraph.subtitle r << %Q[<p>#{paragraph.body.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</p>\n<p>" )}</p>] else r << %Q[<p><a ] if opt['anchor'] then r << %Q[name="p#{'%02d' % idx}" ] end r << %Q[href="#{opt['index']}<%=anchor "#{@date.strftime( '%Y%m%d' )}#p#{'%02d' % idx}" %>">#{opt['section_anchor']}</a> #{paragraph.body.collect{|l|l.chomp.sub( /^[ ]/u, '' )}.join( "</p>\n<p>" )}</p>] end r << %Q[</div>] idx += 1 end r end |
#to_s ⇒ Object
246 247 248 |
# File 'lib/tdiary/io/pstore.rb', line 246 def to_s "date=#{@date.strftime('%Y%m%d')}, title=#{@title}, body=[#{@paragraphs.join('][')}]" end |
#to_src ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/tdiary/io/pstore.rb', line 173 def to_src src = '' each_section do |para| src << para.to_src end src end |