Class: Ronin::EmailAddress
- Inherits:
-
Object
- Object
- Ronin::EmailAddress
- Includes:
- Model
- Defined in:
- lib/ronin/email_address.rb
Overview
Represents email addresses that can be stored in the Database.
Class Method Summary collapse
-
.extract(text) {|email| ... } ⇒ Array<EmailAddress>
Extracts email addresses from the given text.
-
.parse(email) ⇒ EmailAddress
Parses an email address.
-
.with_hosts(names) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given host names.
-
.with_ips(ips) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given IP address(es).
-
.with_users(names) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given user names.
Instance Method Summary collapse
-
#host ⇒ String
The host of the email address.
-
#inspect ⇒ String
Inspects the email address.
-
#to_ary ⇒ Array
Splats the email address into multiple variables.
-
#to_s ⇒ String
Converts the email address into a String.
-
#user ⇒ String
The user of the email address.
Methods included from Model
Class Method Details
.extract(text) {|email| ... } ⇒ Array<EmailAddress>
Extracts email addresses from the given text.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ronin/email_address.rb', line 77 def self.extract(text) return enum_for(:extract,text).to_a unless block_given? scanner = StringScanner.new(text) while scanner.skip_until(Regexp::EMAIL_ADDR) yield parse(scanner.matched) end return nil end |
.parse(email) ⇒ EmailAddress
Parses an email address.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/ronin/email_address.rb', line 156 def EmailAddress.parse(email) user, host = email.split('@',2) user.strip! if user.empty? raise("email address #{email.dump} must have a user name") end host.strip! if host.empty? raise("email address #{email.dump} must have a host name") end return EmailAddress.first_or_new( :user_name => UserName.first_or_new(:name => user), :host_name => HostName.first_or_new(:address => host) ) end |
.with_hosts(names) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given host names.
102 103 104 |
# File 'lib/ronin/email_address.rb', line 102 def self.with_hosts(names) all('host_name.address' => names) end |
.with_ips(ips) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given IP address(es).
119 120 121 |
# File 'lib/ronin/email_address.rb', line 119 def self.with_ips(ips) all('ip_addresses.address' => ips) end |
.with_users(names) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given user names.
136 137 138 |
# File 'lib/ronin/email_address.rb', line 136 def self.with_users(names) all('user_name.name' => names) end |
Instance Method Details
#host ⇒ String
The host of the email address.
201 202 203 |
# File 'lib/ronin/email_address.rb', line 201 def host self.host_name.address if self.host_name end |
#inspect ⇒ String
Inspects the email address.
229 230 231 |
# File 'lib/ronin/email_address.rb', line 229 def inspect "#<#{self.class}: #{self}>" end |
#to_ary ⇒ Array
Splats the email address into multiple variables.
252 253 254 |
# File 'lib/ronin/email_address.rb', line 252 def to_ary [self.user_name.name, self.host_name.address] end |
#to_s ⇒ String
Converts the email address into a String.
215 216 217 |
# File 'lib/ronin/email_address.rb', line 215 def to_s "#{self.user_name}@#{self.host_name}" end |
#user ⇒ String
The user of the email address.
187 188 189 |
# File 'lib/ronin/email_address.rb', line 187 def user self.user_name.name if self.user_name end |