module Helper
Public Instance Methods
create_email_struct(emails)
click to toggle source
# File lib/mc/helper.rb, line 27 def create_email_struct(emails) struct = [] emails.each do |email| struct << {:email => email} end return struct end
get_last_campaign_id(really=false)
click to toggle source
# File lib/mc/helper.rb, line 22 def get_last_campaign_id(really=false) #do we really want to use the last campaign id? really ? @mailchimp_cached.campaigns_list(:limit => 1, :sort_field => "create_time")["data"].first["id"] : nil end
na(item)
click to toggle source
# File lib/mc/helper.rb, line 2 def na(item) if item.nil? return "NA" elsif item.is_a? Float '%.2f' % item else item end end
not_implemented()
click to toggle source
# File lib/mc/helper.rb, line 36 def not_implemented raise "This command is not implemented yet." end
required_argument(msg, *arguments)
click to toggle source
# File lib/mc/helper.rb, line 17 def required_argument(msg, *arguments) arguments.each {|a| return a unless a.nil? or a.empty?} exit_now!(msg) end
required_option(name, *options)
click to toggle source
# File lib/mc/helper.rb, line 12 def required_option(name, *options) options.each {|o| return o unless o.nil? or o.empty?} exit_now!("Error: --#{name.to_s} is required") end
show_errors(status)
click to toggle source
# File lib/mc/helper.rb, line 53 def show_errors status if status['error_count'] > 0 puts "Oops, had #{status['error_count']} error(s):" status['errors'].each do |error| # remove periods just to make the error look nicer puts " #{error['error'].gsub('.','')} - #{error['email']['email']}" end end end
successful?(status)
click to toggle source
# File lib/mc/helper.rb, line 49 def successful? status status['success_count'] > 0 end
view_to_print(global, fields, print_options=nil)
click to toggle source
# File lib/mc/helper.rb, line 40 def view_to_print(global, fields, print_options=nil) if global[:raw] # only show the first field and nothing else return fields.first, {:show_index => false} else return fields, print_options end end
Private Instance Methods
pad(num, total)
click to toggle source
# File lib/mc/helper.rb, line 65 def pad(num, total) padding = "" amount_to_pad = total.to_s.size - num.to_s.size amount_to_pad.times {padding << " "} padding + num.to_s end