Class: Hermeneutics::AddrList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hermeneutics/addrs.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(cont) ⇒ Object



563
564
565
566
# File 'lib/hermeneutics/addrs.rb', line 563

def parse cont
  str = HeaderExt.decode cont
  new.add_quoted str
end

Instance Method Details

#==(str) ⇒ Object



650
651
652
# File 'lib/hermeneutics/addrs.rb', line 650

def == str
  @list.find { |a| a == str }
end

#add(mail, real = nil) ⇒ Object



654
655
656
657
658
659
660
# File 'lib/hermeneutics/addrs.rb', line 654

def add mail, real = nil
  if real or not Addr === mail then
    mail = Addr.create mail, real
  end
  @list.push mail
  self
end

#add_quoted(str) ⇒ Object



662
663
664
665
666
667
# File 'lib/hermeneutics/addrs.rb', line 662

def add_quoted str
  Addr.parse str.to_s do |a,|
    @list.push a
  end
  self
end

#eachObject

:call-seq:

each { |addr| ... }     -> self

Call block for each address.



617
618
619
# File 'lib/hermeneutics/addrs.rb', line 617

def each
  @list.each { |a| yield a }
end

#empty?Boolean

Returns:

  • (Boolean)


578
# File 'lib/hermeneutics/addrs.rb', line 578

def empty?    ; @list.empty?            ; end

#encodeObject



603
604
605
606
607
608
609
610
# File 'lib/hermeneutics/addrs.rb', line 603

def encode
  r = []
  @list.map { |a|
    if r.last then r.last << "," end
    r.push a.encode.dup
  }
  r
end

#has?(*mails) ⇒ Boolean Also known as: has

Returns:

  • (Boolean)


622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/hermeneutics/addrs.rb', line 622

def has? *mails
  mails.flatten!
  mails.find { |m|
    case m
      when Regexp then
        @list.find { |a|
          if a.plain =~ m then
            yield *$~.captures if block_given?
            true
          end
        }
      else
        self == m
    end
  }
end

#inspectObject



591
592
593
# File 'lib/hermeneutics/addrs.rb', line 591

def inspect
  "<#{self.class}: " + (@list.map { |a| a.inspect }.join ", ") + ">"
end

#notempty?Boolean

Returns:

  • (Boolean)


579
# File 'lib/hermeneutics/addrs.rb', line 579

def notempty? ; self if @list.notempty? ; end

#push(addrs) ⇒ Object Also known as: <<



581
582
583
584
585
586
587
588
# File 'lib/hermeneutics/addrs.rb', line 581

def push addrs
  case addrs
    when nil    then
    when String then add_quoted addrs
    when Addr   then @list.push addrs
    else             addrs.each { |a| push a }
  end
end

#quoteObject



599
600
601
# File 'lib/hermeneutics/addrs.rb', line 599

def quote
  @list.map { |a| a.quote }.join ", "
end

#to_sObject



595
596
597
# File 'lib/hermeneutics/addrs.rb', line 595

def to_s
  @list.map { |a| a.to_s }.join ", "
end

#under_domain(*args) ⇒ Object



640
641
642
643
644
645
646
647
648
# File 'lib/hermeneutics/addrs.rb', line 640

def under_domain *args
  @list.each { |a|
    a.plain =~ /(.*)@/ or next
    l, d = $1, $'
    case d
      when *args then yield l
    end
  }
end