Class: EmailReplyParser::Fragment

Inherits:
Struct
  • Object
show all
Defined in:
lib/email_reply_parser/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.



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

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.



432
433
434
# File 'lib/email_reply_parser/email_reply_parser.rb', line 432

def content
  @content
end

#current_blockObject (readonly)

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



428
429
430
# File 'lib/email_reply_parser/email_reply_parser.rb', line 428

def current_block
  @current_block
end

#hiddenObject Also known as: hidden?

Returns the value of attribute hidden

Returns:

  • (Object)

    the current value of hidden



422
423
424
# File 'lib/email_reply_parser/email_reply_parser.rb', line 422

def hidden
  @hidden
end

#linesObject (readonly)

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



424
425
426
# File 'lib/email_reply_parser/email_reply_parser.rb', line 424

def lines
  @lines
end

#quotedObject Also known as: quoted?

Returns the value of attribute quoted

Returns:

  • (Object)

    the current value of quoted



422
423
424
# File 'lib/email_reply_parser/email_reply_parser.rb', line 422

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



422
423
424
# File 'lib/email_reply_parser/email_reply_parser.rb', line 422

def reply_header
  @reply_header
end

#signatureObject Also known as: signature?

Returns the value of attribute signature

Returns:

  • (Object)

    the current value of signature



422
423
424
# File 'lib/email_reply_parser/email_reply_parser.rb', line 422

def signature
  @signature
end

Instance Method Details

#add_line(line) ⇒ Object



446
447
448
449
450
451
452
453
454
# File 'lib/email_reply_parser/email_reply_parser.rb', line 446

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.



461
462
463
464
# File 'lib/email_reply_parser/email_reply_parser.rb', line 461

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

#inspectObject



470
471
472
# File 'lib/email_reply_parser/email_reply_parser.rb', line 470

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

#to_sObject



466
467
468
# File 'lib/email_reply_parser/email_reply_parser.rb', line 466

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