Class: Sem4r::CriterionKeyword

Inherits:
Criterion show all
Defined in:
lib/sem4r/ad_group_criterion/criterion_keyword.rb

Instance Attribute Summary

Attributes inherited from Criterion

#ad_group, #type

Attributes inherited from Base

#adwords, #credentials, #service

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Criterion

#ad_param, #id, #saved?

Methods inherited from Base

#add_counters

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(ad_group, text = nil, match = "BROAD", &block) ⇒ CriterionKeyword

Returns a new instance of CriterionKeyword.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 33

def initialize(ad_group, text = nil, match = "BROAD", &block)
  super( ad_group )
  self.type = Keyword
  self.text = text   unless text.nil?     # TODO: text == nil raise error
  self.match = match unless match.nil?
  if block_given?
    @inside_initialize = true
    block.arity < 1 ? instance_eval(&block) : block.call(self)
  end
  @inside_initialize = false
end

Class Method Details

.create(ad_group, &block) ⇒ Object



49
50
51
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 49

def self.create(ad_group, &block)
  new(ad_group, &block).save
end

.from_element(ad_group, el) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 53

def self.from_element( ad_group, el )
  new(ad_group) do
    @id      = el.at_xpath("id").text.strip.to_i
    text       el.at_xpath("text").text.strip
    match      el.at_xpath("matchType").text.strip
  end
end

Instance Method Details

#inside_initialize?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 45

def inside_initialize?
  @inside_initialize
end

#to_sObject



61
62
63
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 61

def to_s
  "#{saved? ? id : 'unsaved' } #{type} #{text} #{match}"
end

#to_xml(tag) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 72

def to_xml(tag)
  builder = Builder::XmlMarkup.new
  builder.tag!(tag, "xsi:type" => "#{type}") do |t|
    t.text        text
    t.matchType   match
  end
end

#xml(t) ⇒ Object



65
66
67
68
69
70
# File 'lib/sem4r/ad_group_criterion/criterion_keyword.rb', line 65

def xml(t)
  t.criterion("xsi:type" => "#{type}") { |t| 
    t.text        text
    t.matchType   match
  }
end