Class: EMaily::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/emaily/templates.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, content_type, ports = nil, site = nil) ⇒ Template

Returns a new instance of Template.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/emaily/templates.rb', line 8

def initialize(template, content_type, ports=nil, site=nil)
  file = File.readlines(template)
  if file[0].match(/<subject>/)
    @s = file[0].scan(/<subject>(.*)<\/subject>/)[0][0]
    @templete=file[1..-1].to_s
  else
    @templete = file.to_s
  end
  @c = content_type
  if ports != nil
    @port = ports
  elsif @templete.match(/%%payload\[(.*)\]%%/) != nil
    puts "I'm here"
    @ports = @templete.scan(/%%payload\[(.*)\]%%/)[0][0].split(",").map {|p| p.to_i}
  else
    @ports = Array.new
  end
  @site = site
end

Instance Attribute Details

#bidlyObject

Returns the value of attribute bidly.



27
28
29
# File 'lib/emaily/templates.rb', line 27

def bidly
  @bidly
end

#portsObject

Returns the value of attribute ports.



27
28
29
# File 'lib/emaily/templates.rb', line 27

def ports
  @ports
end

#site=(url) ⇒ Object



52
53
54
# File 'lib/emaily/templates.rb', line 52

def site=(url)
  @site = url.match(/http/) ? url : "http://#{url}"
end

Instance Method Details

#generate_email(values) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/emaily/templates.rb', line 30

def generate_email(values)
  email = @templete.clone
  D "Creating Email for #{values[:email]}" if values[:email]
  email.scan(/(%%.*%%)/).each {|x| email.gsub!(/(#{x[0]})/) {|s| values[s.to_s[2...-2].to_sym]}}
  email.gsub!(/%%payload\[.*\]%%/) { |pl| generate_scan_ports(values[:email])}
  email
end

#generate_email_with_scan(values) ⇒ Object

Method not used yet. It will be used when needed :)



39
40
41
42
# File 'lib/emaily/templates.rb', line 39

def generate_email_with_scan(values)
  email = generate_email(values)
  email.gsub!(/(<\/body>)/) {|s| "#{scan_ports(@ports, values[:email])}" + s }
end

#is_html?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/emaily/templates.rb', line 48

def is_html?
  @c.match(/text\/html/) != nil ? true : false
end

#is_text?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/emaily/templates.rb', line 44

def is_text?
  @c.match(/text\/plain/) != nil ? true : false
end

#subjectObject



56
57
58
# File 'lib/emaily/templates.rb', line 56

def subject
  @s || nil
end