Class: Sem4r::ManualCPCAdGroupCriterionBids

Inherits:
AdGroupCriterionBids show all
Defined in:
lib/sem4r/ad_group_criterion/ad_group_criterion_bids.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) ⇒ ManualCPCAdGroupCriterionBids

Returns a new instance of ManualCPCAdGroupCriterionBids.



59
60
61
62
63
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb', line 59

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

Class Method Details

.from_element(el) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb', line 65

def self.from_element(el)
  new do
    bid_source       el.at_xpath("bidSource").text.strip

    el_maxCpc = el.at_xpath("maxCpc")
    el_amount = el_maxCpc.at_xpath("amount")
    max_cpc     el_amount.at_xpath("microAmount").text.strip.to_i
    # TODO: it is possible something like:
    #        el.elements["maxCpc"] do |el|
    #          el.elements["amount"] do el
    #            max_cpc el["microAmount"]
    #          end
    #        end
  end
end

Instance Method Details

#to_sObject



106
107
108
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb', line 106

def to_s
  "#{@maxcpc / 10000} cents"
end

#to_xml(tag = 'bids') ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb', line 93

def to_xml(tag = 'bids')
  builder = Builder::XmlMarkup.new
  xml = builder.tag!(tag, 'xsi:type' => 'ManualCPCAdGroupCriterionBids') { |xml|
    xml.tag!('AdGroupCriterionBids.Type') { xml.text! 'ManualCPCAdGroupCriterionBids' }
    xml.maxCpc {
      xml.amount {
        xml.tag!('ComparableValue.Type') { xml.text! 'Money' }
        xml.microAmount max_cpc
      }
    }
  }
end

#xml(t) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb', line 81

def xml(t)
  t.tag!('bids', 'xsi:type' => 'ManualCPCAdGroupCriterionBids') {
    t.tag!('AdGroupCriterionBids.Type') { t.text! 'ManualCPCAdGroupCriterionBids' }
    t.maxCpc {
      t.amount {
        t.tag!('ComparableValue.Type') { t.text! 'Money' }
        t.microAmount max_cpc
      }
    }
  }
end