Class: MailxRuby::CommandGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/mailx_ruby/command_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ CommandGenerator

Returns a new instance of CommandGenerator.



9
10
11
# File 'lib/mailx_ruby/command_generator.rb', line 9

def initialize(attributes)
  assign_attributes attributes
end

Instance Attribute Details

#bccObject

Returns the value of attribute bcc.



3
4
5
# File 'lib/mailx_ruby/command_generator.rb', line 3

def bcc
  @bcc
end

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/mailx_ruby/command_generator.rb', line 3

def body
  @body
end

#ccObject

Returns the value of attribute cc.



3
4
5
# File 'lib/mailx_ruby/command_generator.rb', line 3

def cc
  @cc
end

#htmlObject

Returns the value of attribute html.



3
4
5
# File 'lib/mailx_ruby/command_generator.rb', line 3

def html
  @html
end

#subjectObject

Returns the value of attribute subject.



3
4
5
# File 'lib/mailx_ruby/command_generator.rb', line 3

def subject
  @subject
end

#toObject

Returns the value of attribute to.



3
4
5
# File 'lib/mailx_ruby/command_generator.rb', line 3

def to
  @to
end

Class Method Details

.execute(options) ⇒ Object



5
6
7
# File 'lib/mailx_ruby/command_generator.rb', line 5

def self.execute(options)
  new(options).execute
end

Instance Method Details

#executeObject



13
14
15
# File 'lib/mailx_ruby/command_generator.rb', line 13

def execute
  `#{generate}`
end

#generateObject



31
32
33
34
35
# File 'lib/mailx_ruby/command_generator.rb', line 31

def generate
  "mailx #{options_string} #{stringify(to)} <<-\"EOM\"
#{inline_css_body}
EOM"
end

#inline_css_bodyObject



21
22
23
24
25
26
27
28
29
# File 'lib/mailx_ruby/command_generator.rb', line 21

def inline_css_body
  if !html
    body.text
  elsif body.has_css?
    body.to_inline_css
  else
    body.to_plain_text
  end
end

#options_stringObject



37
38
39
40
41
# File 'lib/mailx_ruby/command_generator.rb', line 37

def options_string
  options_hash.map do |key, value|
    "-#{key} \"#{value}\""
  end.join(" ")
end

#subject_with_headersObject



43
44
45
46
47
48
49
# File 'lib/mailx_ruby/command_generator.rb', line 43

def subject_with_headers
  if html
    "$(echo \"#{subject}\nContent-Type: text/html\")"
  else
    subject
  end
end