Class: Mbox::Mail::Headers::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/mbox/mail/headers.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Name

Returns a new instance of Name


37
38
39
40
41
42
43
44
45
# File 'lib/mbox/mail/headers.rb', line 37

def initialize (name)
	name = name.to_s.downcase.gsub('-', '_').to_sym

	if name.empty?
		raise ArgumentError, 'cannot pass empty name'
	end

	@internal = name
end

Class Method Details

.parse(text) ⇒ Object


31
32
33
34
35
# File 'lib/mbox/mail/headers.rb', line 31

def self.parse (text)
	return text if text.is_a? self

	new(text)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?


47
48
49
# File 'lib/mbox/mail/headers.rb', line 47

def == (other)
	to_sym == Name.parse(other).to_sym
end

#hashObject


53
54
55
# File 'lib/mbox/mail/headers.rb', line 53

def hash
	to_sym.hash
end

#to_sObject Also known as: to_str


62
63
64
65
66
# File 'lib/mbox/mail/headers.rb', line 62

def to_s
	to_sym.to_s.downcase.gsub('_', '-').gsub(/(\A|-)(.)/) {|match|
		match.upcase
	}
end

#to_symObject


57
58
59
# File 'lib/mbox/mail/headers.rb', line 57

def to_sym
	@internal
end