class MailxRuby::CommandGenerator
Attributes
bcc[RW]
body[RW]
cc[RW]
html[RW]
subject[RW]
to[RW]
Public Class Methods
execute(options)
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 5 def self.execute(options) new(options).execute end
new(attributes)
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 9 def initialize(attributes) assign_attributes attributes end
Private Class Methods
symbolize_keys(hash)
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 52 def self.symbolize_keys(hash) hash.map{|k,v| [k.to_sym, v] }.to_h end
Public Instance Methods
body=(body_text)
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 17 def body=(body_text) @body = Body.new(body_text) end
execute()
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 13 def execute `#{generate}` end
generate()
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 31 def generate "mailx #{options_string} #{stringify(to)} <<-\"EOM\" #{inline_css_body} EOM" end
inline_css_body()
click to toggle source
# 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_string()
click to toggle source
# 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_headers()
click to toggle source
# 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
Private Instance Methods
assign_attributes(attributes)
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 56 def assign_attributes(attributes) attributes.each do |key, value| send("#{key}=", value) end end
options_hash()
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 62 def options_hash { s: subject_with_headers, c: stringify(cc), b: stringify(bcc), }.select{|k,v| v } end
stringify(arr_or_string)
click to toggle source
# File lib/mailx_ruby/command_generator.rb, line 70 def stringify(arr_or_string) return nil unless arr_or_string arr_or_string.is_a?(Array) ? arr_or_string.join(",") : arr_or_string.to_s end