Class: Sem4r::TargetingIdea

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(&block) ⇒ TargetingIdea

Returns a new instance of TargetingIdea.



52
53
54
55
56
# File 'lib/sem4r/targeting_idea/targeting_idea.rb', line 52

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



50
51
52
# File 'lib/sem4r/targeting_idea/targeting_idea.rb', line 50

def attributes
  @attributes
end

Class Method Details

.from_element(el) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sem4r/targeting_idea/targeting_idea.rb', line 58

def self.from_element(el)
  els = el.xpath("data")
  @attributes = els.map do |el|
    el1 = el.at_xpath("value")
    xml_type = el1.at_xpath("Attribute.Type").text.strip
    case xml_type
    when IdeaTypeAttribute
      TIdeaTypeAttribute.from_element(el1)
    when KeywordAttribute
      TKeywordAttribute.from_element(el1)
    when MonthlySearchVolumeAttribute
      TMonthlySearchVolumeAttribute.from_element(el1)
    else
      # added from biilmann trunk
      Struct.new(:key, :text).new(
        el.xpath("key").text.strip,
        el1.xpath("value").text.strip)
    end
  end
end

Instance Method Details

#to_sObject



79
80
81
# File 'lib/sem4r/targeting_idea/targeting_idea.rb', line 79

def to_s
  @attributes.collect { |attr| attr.to_s }.join("\n")
end