Class: Paragraph

Inherits:
Object
  • 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.



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

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.



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

def body
  @body
end

#subtitleObject (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

#authorObject



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

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

#to_sObject



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

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

#to_srcObject



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