Class: TDiary::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, mail, body, date = Time::now) ⇒ Comment

Returns a new instance of Comment.



9
10
11
12
# File 'lib/tdiary/comment.rb', line 9

def initialize( name, mail, body, date = Time::now )
	@name, @mail, @body, @date = name, mail, body, date
	@show = true
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/tdiary/comment.rb', line 7

def body
  @body
end

#dateObject (readonly)

Returns the value of attribute date.



7
8
9
# File 'lib/tdiary/comment.rb', line 7

def date
  @date
end

#mailObject (readonly)

Returns the value of attribute mail.



7
8
9
# File 'lib/tdiary/comment.rb', line 7

def mail
  @mail
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/tdiary/comment.rb', line 7

def name
  @name
end

Instance Method Details

#==(c) ⇒ Object



27
28
29
# File 'lib/tdiary/comment.rb', line 27

def ==( c )
	(@name == c.name) and (@mail == c.mail) and (@body == c.body)
end

#shorten(length = 120) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/tdiary/comment.rb', line 14

def shorten( length = 120 )
	matched = body.gsub( /\n/, ' ' ).scan( /^.{0,#{length - 2}}/u )[0]

	unless $'.empty? then
		matched + '..'
	else
		matched
	end
end

#show=(s) ⇒ Object



25
# File 'lib/tdiary/comment.rb', line 25

def show=( s ); @show = s; end

#visible?Boolean

Returns:

  • (Boolean)


24
# File 'lib/tdiary/comment.rb', line 24

def visible?; @show; end