Class: Ronin::Campaign

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Timestamps, Model, Model::HasDescription, Model::HasUniqueName
Defined in:
lib/ronin/campaign.rb

Overview

Represents a grouping of targeted Addresses.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::HasDescription

included

Methods included from Model::HasUniqueName

included

Methods included from Model

included

Class Method Details

.targeting(addr) ⇒ Array<Campaign>

Searches for all campaigns targeting an Address.

Parameters:

  • addr (Array<String>, String)

    The address(es) to search for.

Returns:

  • (Array<Campaign>)

    The campaigns that target the given address.

Since:

  • 1.0.0


66
67
68
# File 'lib/ronin/campaign.rb', line 66

def self.targeting(addr)
  all('addresses.address' => addr)
end

.targeting_orgs(names) ⇒ Array<Campaign>

Searches for all campaigns targeting an Organization.

Parameters:

  • names (Array<String>, String)

    The organization name(s) to search for.

Returns:

  • (Array<Campaign>)

    The campaigns that target the specified organizations.

Since:

  • 1.0.0


83
84
85
# File 'lib/ronin/campaign.rb', line 83

def self.targeting_orgs(names)
  all('organizations.name' => names)
end

Instance Method Details

#target!(addr) ⇒ Target

Adds an address to the campaign.

Parameters:

  • addr (String)

    The address that will be targeted.

Returns:

  • (Target)

    The new target of the campaign.

Raises:

  • (RuntimeError)

    The given address could not be found.

Since:

  • 1.0.0


120
121
122
123
124
125
126
# File 'lib/ronin/campaign.rb', line 120

def target!(addr)
  unless (address = Address.first(:address => addr))
    raise("unknown address #{addr.dump}")
  end

  return Target.first_or_create(:campaign => self, :address => address)
end

#targets?(addr) ⇒ Boolean

Determines if an address is targeted by the campaign.

Parameters:

  • address (Address)

    The address.

Returns:

  • (Boolean)

    Specifies whether the address is targeted.

Since:

  • 1.0.0


100
101
102
# File 'lib/ronin/campaign.rb', line 100

def targets?(addr)
  self.addresses.include?(address)
end