Class: EmailReplyParser::Fragment

Inherits:
Struct
  • Object
show all
Defined in:
lib/email_reply_parser.rb

Overview

Represents a group of paragraphs in the email sharing common attributes. Paragraphs should get their own fragment if they are a quoted area or a signature.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFragment

Returns a new instance of Fragment.



407
408
409
410
411
412
# File 'lib/email_reply_parser.rb', line 407

def initialize
  self.quoted = self.signature = self.reply_header = self.hidden = false
  @lines = []
  @current_block = []
  @content = nil
end

Instance Attribute Details

#contentObject (readonly)

This is reserved for the joined String that is build when this Fragment is finished.



405
406
407
# File 'lib/email_reply_parser.rb', line 405

def content
  @content
end

#current_blockObject (readonly)

Array of string lines that is being processed not having an empty line.



401
402
403
# File 'lib/email_reply_parser.rb', line 401

def current_block
  @current_block
end

#hiddenObject Also known as: hidden?

Returns the value of attribute hidden

Returns:

  • (Object)

    the current value of hidden



395
396
397
# File 'lib/email_reply_parser.rb', line 395

def hidden
  @hidden
end

#linesObject (readonly)

Array of string lines that make up the content of this fragment.



397
398
399
# File 'lib/email_reply_parser.rb', line 397

def lines
  @lines
end

#quotedObject Also known as: quoted?

Returns the value of attribute quoted

Returns:

  • (Object)

    the current value of quoted



395
396
397
# File 'lib/email_reply_parser.rb', line 395

def quoted
  @quoted
end

#reply_headerObject Also known as: reply_header?

Returns the value of attribute reply_header

Returns:

  • (Object)

    the current value of reply_header



395
396
397
# File 'lib/email_reply_parser.rb', line 395

def reply_header
  @reply_header
end

#signatureObject Also known as: signature?

Returns the value of attribute signature

Returns:

  • (Object)

    the current value of signature



395
396
397
# File 'lib/email_reply_parser.rb', line 395

def signature
  @signature
end

Instance Method Details

#add_line(line) ⇒ Object



419
420
421
422
423
424
425
426
427
# File 'lib/email_reply_parser.rb', line 419

def add_line(line)
  return unless line
  @lines.insert(0, line)
  if line == ""
    @current_block.clear
  else
    @current_block.insert(0, line)
  end
end

#finishObject

Builds the string content by joining the lines and reversing them.



434
435
436
437
# File 'lib/email_reply_parser.rb', line 434

def finish
  @content = @lines.join("\n")
  @lines = @current_block = nil
end

#inspectObject



443
444
445
# File 'lib/email_reply_parser.rb', line 443

def inspect
  "#{super.inspect} : #{to_s.inspect}"
end

#to_sObject



439
440
441
# File 'lib/email_reply_parser.rb', line 439

def to_s
  @lines ? @lines.join("\n") : @content
end