Module: Helper

Defined in:
lib/mc/helper.rb

Instance Method Summary collapse

Instance Method Details

#create_email_struct(emails) ⇒ Object



27
28
29
30
31
32
33
34
# 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) ⇒ Object



22
23
24
25
# 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) ⇒ Object



2
3
4
5
6
7
8
9
10
# 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_implementedObject



36
37
38
# File 'lib/mc/helper.rb', line 36

def not_implemented
  raise "This command is not implemented yet."
end

#required_argument(msg, *arguments) ⇒ Object



17
18
19
20
# 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) ⇒ Object



12
13
14
15
# 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) ⇒ Object



53
54
55
56
57
58
59
60
61
# 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) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/mc/helper.rb', line 49

def successful? status
  status['success_count'] > 0
end

#view_to_print(global, fields, print_options = nil) ⇒ Object



40
41
42
43
44
45
46
47
# 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