Class: Deb822::FieldName

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

Constant Summary collapse

PATTERN =

> The field name is composed of US-ASCII characters excluding control characters, space, and colon > (i.e., characters in the ranges U+0021 ‘!’ through U+0039 ‘9’, and U+003B ‘;’ through U+007E ‘~’, inclusive). > Field names must not begin with the comment character (U+0023 ‘#’), nor with the hyphen character (U+002D ‘-’).

/[!"$-,.-9;-~][!-9;-~]*/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ FieldName

Returns a new instance of FieldName.



23
24
25
26
27
28
29
30
31
# File 'lib/deb822.rb', line 23

def initialize(name)
  name = name.to_s unless name.is_a?(String)

  unless /\A#{PATTERN}\z/o.match?(name)
    raise InvalidFieldName, "Invalid field name: #{name.inspect}"
  end

  @sym = FieldName.canonicalize(name).to_sym
end

Class Method Details

.canonicalize(str) ⇒ Object



61
62
63
# File 'lib/deb822.rb', line 61

def self.canonicalize(str)
  str.split(?-).each {|s| s.capitalize!(:ascii) }.join(?-)
end

Instance Method Details

#!=(other) ⇒ Object



53
54
55
# File 'lib/deb822.rb', line 53

def !=(other)
  !eql?(other)
end

#==(other) ⇒ Object



49
50
51
# File 'lib/deb822.rb', line 49

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/deb822.rb', line 45

def eql?(other)
  to_sym == Deb822::FieldName(other).to_sym
end

#hashObject



41
42
43
# File 'lib/deb822.rb', line 41

def hash
  @sym.hash
end

#inspectObject



57
58
59
# File 'lib/deb822.rb', line 57

def inspect
  @sym
end

#to_sObject



37
38
39
# File 'lib/deb822.rb', line 37

def to_s
  @sym.to_s
end

#to_symObject



33
34
35
# File 'lib/deb822.rb', line 33

def to_sym
  @sym
end