Class: Sem4r::TargetingIdeaSelector

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

Instance Method Summary collapse

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(&block) ⇒ TargetingIdeaSelector

Returns a new instance of TargetingIdeaSelector.



155
156
157
158
159
160
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 155

def initialize(&block)
  @search_parameters = []
  if block_given?
    block.arity < 1 ? instance_eval(&block) : block.call(self)
  end
end

Instance Method Details

#country_target_search_parameter(&block) ⇒ Object



175
176
177
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 175

def country_target_search_parameter(&block)
  @search_parameters << CountryTargetSearchParameter.new(&block)
end

#excluded_keyword_search_parameter(&block) ⇒ Object



167
168
169
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 167

def excluded_keyword_search_parameter(&block)
  @search_parameters << ExcludedKeywordSearchParameter.new(&block)
end

#keyword_match_type_search_parameter(&block) ⇒ Object



171
172
173
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 171

def keyword_match_type_search_parameter(&block)
  @search_parameters << KeywordMatchTypeSearchParameter.new(&block)
end

#ngram_group_search_parameter(&block) ⇒ Object



179
180
181
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 179

def ngram_group_search_parameter(&block)
  @search_parameters << NgramGroupsSearchParameter.new(&block)
end

TODO: synthetize following methods with metaprogramming



163
164
165
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 163

def related_to_keyword_search_parameter(&block)
  @search_parameters << RelatedToKeywordSearchParameter.new(&block)
end

#to_xmlObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/sem4r/targeting_idea/targeting_idea_selector.rb', line 183

def to_xml
  xml=<<-EOFS
   <s:selector>
      <s:ideaType>#{@idea_type}</s:ideaType>
      <s:requestType>#{@request_type}</s:requestType>
  EOFS
  xml += @search_parameters.collect{ |sp| sp.to_xml }.join()
  if requested_attributes
    requested_attributes.each do |requested_attribute|
      xml += <<-EOS
        <s:requestedAttributeTypes>#{requested_attribute.to_s.upcase}</s:requestedAttributeTypes>
      EOS
    end
  end
  xml+=<<-EOFS
    <s:paging>
      <startIndex>#{start_index || 0}</startIndex>
      <numberResults>#{number_results || 100}</numberResults>
    </s:paging>
    </s:selector>
  EOFS
  xml

end