Class: ProcessTag::CampaignProcess

Inherits:
Object
  • Object
show all
Includes:
Process
Defined in:
lib/cm_tag/campaign_process.rb

Constant Summary

Constants included from Process

Process::CDN_EXP, Process::CD_EXP, Process::CMN_EXP, Process::CM_EXP, Process::CY_EXP, Process::DESC_EXP, Process::HREF_EXP, Process::IMAGE_EXP, Process::TTL_EXP

Instance Method Summary collapse

Methods included from Process

#find_all, #find_html_tags, #scan_exp, #transform_campaign_to_html_tags, #update_campaign_tags

Instance Method Details

#get_tagsObject



38
39
40
41
42
43
44
45
46
# File 'lib/cm_tag/campaign_process.rb', line 38

def get_tags
  tags = {}
  tags[:description] = (@description_tags.nil? && []) || @description_tags
  tags[:title] = (@title_tags.nil? && []) || @title_tags
  tags[:image] = (@imgsrc_tags.nil? && []) || @imgsrc_tags
  tags[:href] = (@linkhref_tags.nil? && []) || @linkhref_tags

  tags
end

#process(html) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/cm_tag/campaign_process.rb', line 8

def process(html)
  raise ArgumentError, "Argument [html] cannot be empty" if html.rstrip == ""

  self.find_all(html)
end

#update_tags(html, params = {}, replace_tags = false) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cm_tag/campaign_process.rb', line 14

def update_tags(html, params = {}, replace_tags = false)
  raise ArgumentError, "Argument [params] cannot be empty" unless params.length > 0
  raise ArgumentError, "Argument [html] cannot be empty" if html.rstrip == ""

  #load the html tags
  self.find_all(html)

  html = self.update_campaign_tags(html, params, (@description_tags.nil? && []) || @description_tags)
  html = self.update_campaign_tags(html, params, (@title_tags.nil? && []) || @title_tags)
  html = self.update_campaign_tags(html, params, (@imgsrc_tags.nil? && []) || @imgsrc_tags)
  html = self.update_campaign_tags(html, params, (@linkhref_tags.nil? && []) || @linkhref_tags)

  puts "replace tags #{replace_tags}"

  if replace_tags
    html = self.transform_campaign_to_html_tags(html, params, (@description_tags.nil? && []) || @description_tags)
    html = self.transform_campaign_to_html_tags(html, params, (@title_tags.nil? && []) || @title_tags)
    html = self.transform_campaign_to_html_tags(html, params, (@imgsrc_tags.nil? && []) || @imgsrc_tags)
    html = self.transform_campaign_to_html_tags(html, params, (@linkhref_tags.nil? && []) || @linkhref_tags)
  end

  html
end