Class: Sem4r::AdGroupCriterion

Inherits:
Object
  • Object
show all
Includes:
Sem4rSoap::SoapAttributes
Defined in:
lib/sem4r/ad_group_criterion/ad_group_criterion.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(&block) ⇒ AdGroupCriterion

Returns a new instance of AdGroupCriterion.



35
36
37
38
39
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion.rb', line 35

def initialize(&block)
  if block_given?
    block.arity < 1 ? instance_eval(&block) : block.call(self)
  end
end

Class Method Details

.from_element(ad_group, el) ⇒ Object



41
42
43
44
45
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion.rb', line 41

def self.from_element(ad_group, el)
  type =  el.at_xpath("AdGroupCriterion.Type").text.strip
  klass = Module::const_get(type)
  klass.from_element(ad_group, el)
end

Instance Method Details

#saveObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion.rb', line 51

def save
  unless criterion.saved?
    o = AdGroupCriterionOperation.new.add(self)
    soap_message =
      criterion.service.ad_group_criterion.mutate( credentials, o.to_xml("operations") )
    criterion.add_counters( soap_message.counters )
    rval = soap_message.response.xpath("//mutateResponse/rval").first
    id = rval.xpath("value/criterion/id").first
    criterion.instance_eval{ @id = id.text.strip.to_i }
  end
  self
end

#saved?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion.rb', line 47

def saved?
  criterion.saved?
end