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



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

def parse cont
  new.add_encoded cont
end

Instance Method Details

#==(str) ⇒ Object



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

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

#add(mail, real = nil) ⇒ Object



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

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



684
685
686
687
688
689
# File 'lib/hermeneutics/addrs.rb', line 684

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

#add_quoted(str) ⇒ Object



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

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.



632
633
634
# File 'lib/hermeneutics/addrs.rb', line 632

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?    ; @list.empty?            ; end

#encodeObject



618
619
620
621
622
623
624
625
# File 'lib/hermeneutics/addrs.rb', line 618

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)


637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/hermeneutics/addrs.rb', line 637

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



606
607
608
# File 'lib/hermeneutics/addrs.rb', line 606

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

#notempty?Boolean

Returns:

  • (Boolean)


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

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

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



596
597
598
599
600
601
602
603
# File 'lib/hermeneutics/addrs.rb', line 596

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



614
615
616
# File 'lib/hermeneutics/addrs.rb', line 614

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

#to_sObject



610
611
612
# File 'lib/hermeneutics/addrs.rb', line 610

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

#under_domain(*args) ⇒ Object



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

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