Class: ABMeter::Core::AssignmentConfig::Audience
- Inherits:
-
Object
- Object
- ABMeter::Core::AssignmentConfig::Audience
- Defined in:
- lib/abmeter/core/assignment_config/audience.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id:, type:) ⇒ Audience
constructor
A new instance of Audience.
- #matches?(user) ⇒ Boolean
- #serialize ⇒ Object
Constructor Details
#initialize(id:, type:) ⇒ Audience
Returns a new instance of Audience.
9 10 11 12 |
# File 'lib/abmeter/core/assignment_config/audience.rb', line 9 def initialize(id:, type:) @id = id @type = type end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/abmeter/core/assignment_config/audience.rb', line 7 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/abmeter/core/assignment_config/audience.rb', line 7 def type @type end |
Class Method Details
.from_json(audience) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/abmeter/core/assignment_config/audience.rb', line 25 def self.from_json(audience) case audience[:type] when 'user_list' UserListAudience.new(id: audience[:id], user_ids: audience[:user_ids]) when 'predicate' PredicateAudience.new(id: audience[:id], predicate: audience[:predicate]) when 'random' RandomAudience.new(id: audience[:id], range: Range.new(*audience[:range])) else raise "Unknown audience type: #{audience[:type]}" end end |
Instance Method Details
#matches?(user) ⇒ Boolean
14 15 16 |
# File 'lib/abmeter/core/assignment_config/audience.rb', line 14 def matches?(user) raise NotImplementedError, 'Subclass must implement this method' end |
#serialize ⇒ Object
18 19 20 21 22 23 |
# File 'lib/abmeter/core/assignment_config/audience.rb', line 18 def serialize { id: id, type: type } end |