Class: Gurgitate::Header
- Inherits:
-
Object
- Object
- Gurgitate::Header
- Defined in:
- lib/gurgitate/header.rb
Overview
A little class for a single header
Instance Attribute Summary collapse
-
#contents ⇒ Object
(also: #value)
The contents of the header.
-
#name ⇒ Object
The name of the header.
Instance Method Summary collapse
-
#<<(text) ⇒ Object
Extended header.
-
#initialize(*header) ⇒ Header
constructor
Creates a Header object.
-
#matches(regex) ⇒ Object
(also: #=~)
Matches a header’s contents.
-
#to_s ⇒ Object
Returns the header, ready to put into an email message.
Constructor Details
#initialize(*header) ⇒ Header
Creates a Header object.
- header
-
The text of the email-message header
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gurgitate/header.rb', line 29 def initialize(*header) name,contents=nil,nil if header.length == 1 then # RFC822 says that a header consists of some (printable, # non-whitespace) crap, followed by a colon, followed by # some more (printable, but can include whitespaces) # crap. if(header[0] =~ /^[\x21-\x39\x3b-\x7e]+:/) then (name,contents)=header[0].split(/:\s*/,2) if(name =~ /:$/ and contents == nil) then # It looks like someone is using Becky! name=header[0].gsub(/:$/,"") contents = "" end raise IllegalHeader, "Empty name" \ if (name == "" or name == nil) contents="" if contents == nil @@lastname=name else raise IllegalHeader, "Bad header syntax: no colon in #{header}" end elsif header.length == 2 then name,contents = *header end @name=capitalize_words(name) @contents=contents end |
Instance Attribute Details
#contents ⇒ Object Also known as: value
The contents of the header
12 13 14 |
# File 'lib/gurgitate/header.rb', line 12 def contents @contents end |
#name ⇒ Object
The name of the header
10 11 12 |
# File 'lib/gurgitate/header.rb', line 10 def name @name end |
Instance Method Details
#<<(text) ⇒ Object
Extended header
61 62 63 |
# File 'lib/gurgitate/header.rb', line 61 def << text @contents += "\n" + text end |
#matches(regex) ⇒ Object Also known as: =~
Matches a header’s contents.
- regex
-
The regular expression to match against the header’s contents
68 69 70 71 72 73 |
# File 'lib/gurgitate/header.rb', line 68 def matches regex if String === regex regex = Regexp.new(Regexp.escape(regex)) end @contents =~ regex end |
#to_s ⇒ Object
Returns the header, ready to put into an email message
78 79 80 |
# File 'lib/gurgitate/header.rb', line 78 def to_s @name+": "+@contents end |