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



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

def parse cont
  new.add_encoded cont
end

Instance Method Details

#==(str) ⇒ Object



658
659
660
# File 'lib/hermeneutics/addrs.rb', line 658

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

#add(mail, real = nil) ⇒ Object



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

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

#add_encoded(cont) ⇒ Object



677
678
679
680
681
682
# File 'lib/hermeneutics/addrs.rb', line 677

def add_encoded cont
  Addr.parse_decode cont.to_s do |a,|
    @list.push a
  end
  self
end

#add_quoted(str) ⇒ Object



670
671
672
673
674
675
# File 'lib/hermeneutics/addrs.rb', line 670

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.



626
627
628
# File 'lib/hermeneutics/addrs.rb', line 626

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

#encodeObject



612
613
614
615
616
617
618
619
# File 'lib/hermeneutics/addrs.rb', line 612

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)


631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/hermeneutics/addrs.rb', line 631

def has? *mails
  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



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

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

#push(addrs) ⇒ Object



591
592
593
594
595
596
597
598
# File 'lib/hermeneutics/addrs.rb', line 591

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

#quoteObject



608
609
610
# File 'lib/hermeneutics/addrs.rb', line 608

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

#to_sObject



604
605
606
# File 'lib/hermeneutics/addrs.rb', line 604

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

#under_domain(*args) ⇒ Object



648
649
650
651
652
653
654
655
656
# File 'lib/hermeneutics/addrs.rb', line 648

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