Class: WatchList::DSL::Context::AlertContact

Inherits:
Object
  • Object
show all
Defined in:
lib/watch_list/dsl/context/alert_contact.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ AlertContact

Returns a new instance of AlertContact.



2
3
4
5
# File 'lib/watch_list/dsl/context/alert_contact.rb', line 2

def initialize(&block)
  @result = {}
  instance_eval(&block)
end

Instance Method Details

#resultObject



7
8
9
10
11
12
13
# File 'lib/watch_list/dsl/context/alert_contact.rb', line 7

def result
  [:Type, :Value].each do |key|
    raise %!AlertContact: "#{key.to_s.downcase}" is required! unless @result[key]
  end

  @result
end

#type(value, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/watch_list/dsl/context/alert_contact.rb', line 15

def type(value, &block)
  if value.kind_of?(Integer)
    alert_contact_type = value
  else
    alert_contact_type = WatchList::AlertContact::Type[value.to_s]
  end

  unless WatchList::AlertContact::Type.values.include?(alert_contact_type)
    raise %!AlertContact: "type" is invalid: #{value.inspect}!
  end

  @result[:Type] = alert_contact_type
end

#value(value) ⇒ Object



29
30
31
32
# File 'lib/watch_list/dsl/context/alert_contact.rb', line 29

def value(value)
  raise %!AlertContact: "value" is invalid: #{value.inspect}! if value.nil?
  @result[:Value] = WatchList::Secure.decrypt_if_possible(value).to_s
end