Class: DMARC::Uri

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

Overview

Represents a DMARC URI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, size = nil, unit = nil) ⇒ Uri

Initializes the DMARC URI.

Parameters:

  • uri (URI::MailTo)

    The mailto: URI.

  • size (Integer) (defaults to: nil)

    The optional maximum-size.

  • unit (:k, :m, :g, :t) (defaults to: nil)

    The optional size unit.

Since:

  • 0.5.0



38
39
40
41
42
43
# File 'lib/dmarc/uri.rb', line 38

def initialize(uri,size=nil,unit=nil)
  @uri = uri

  @size = size
  @unit = unit
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object (protected)

Pass all missing methods to #uri.

Since:

  • 0.5.0



100
101
102
# File 'lib/dmarc/uri.rb', line 100

def method_missing(name,*arguments,&block)
  @uri.send(name,*arguments,&block)
end

Instance Attribute Details

#sizeInteger? (readonly)

The optional maximum-size.

Returns:

  • (Integer, nil)

Since:

  • 0.5.0



19
20
21
# File 'lib/dmarc/uri.rb', line 19

def size
  @size
end

#unit:k, ... (readonly)

The optional unit.

Returns:

  • (:k, :m, :g, :t, nil)

Since:

  • 0.5.0



24
25
26
# File 'lib/dmarc/uri.rb', line 24

def unit
  @unit
end

#uriURI::MailTo (readonly)

The mailto: URI.

Returns:

  • (URI::MailTo)

Since:

  • 0.5.0



14
15
16
# File 'lib/dmarc/uri.rb', line 14

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Boolean

Determines if the DMARC URI matches the other.

Parameters:

  • other (Object)

    the other DMARC URI to compare against.

Returns:

  • (Boolean)

Since:

  • 0.5.0



71
72
73
74
75
76
# File 'lib/dmarc/uri.rb', line 71

def ==(other)
  (self.class == other.class) &&
  (@uri == other.uri) &&
  (@size == other.size) &&
  (@unit == other.unit)
end

#size?Boolean

Determines if a maximum-size was set.

Returns:

  • (Boolean)

Since:

  • 0.5.0



50
51
52
# File 'lib/dmarc/uri.rb', line 50

def size?
  !@size.nil?
end

#to_sString

Converts the DMARC URI back into a String.

Returns:

  • (String)

Since:

  • 0.5.0



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dmarc/uri.rb', line 83

def to_s
  str = @uri.to_s

  if (@size || @unit)
    str << "!"
    str << "#{@size}" if @size
    str << "#{@unit}" if @unit
  end

  return str
end

#unit?Boolean

Determines if a size unit was set.

Returns:

  • (Boolean)

Since:

  • 0.5.0



59
60
61
# File 'lib/dmarc/uri.rb', line 59

def unit?
  !@unit.nil?
end