Module: Helper
- Defined in:
- lib/mc/helper.rb
Instance Method Summary collapse
- #create_email_struct(emails) ⇒ Object
- #get_last_campaign_id ⇒ Object
- #get_required_argument(name, option, global) ⇒ Object
- #na(item) ⇒ Object
- #not_implemented ⇒ Object
- #required_argument(msg, *arguments) ⇒ Object
- #required_option(name, *options) ⇒ Object
- #view_to_print(global, fields, print_options = nil) ⇒ Object
Instance Method Details
#create_email_struct(emails) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/mc/helper.rb', line 32 def create_email_struct(emails) struct = [] emails.each do |email| struct << {:email => email} end return struct end |
#get_last_campaign_id ⇒ Object
28 29 30 |
# File 'lib/mc/helper.rb', line 28 def get_last_campaign_id @mailchimp_cached.campaigns_list(:limit => 1, :sort_field => "create_time")["data"].first["id"] end |
#get_required_argument(name, option, global) ⇒ Object
12 13 14 15 16 |
# File 'lib/mc/helper.rb', line 12 def get_required_argument(name, option, global) return option unless option.nil? return global unless global.nil? help_now!("--#{name.to_s} is required") 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_implemented ⇒ Object
41 42 43 |
# File 'lib/mc/helper.rb', line 41 def not_implemented raise "This command is not implemented yet." end |
#required_argument(msg, *arguments) ⇒ Object
23 24 25 26 |
# File 'lib/mc/helper.rb', line 23 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
18 19 20 21 |
# File 'lib/mc/helper.rb', line 18 def required_option(name, *) .each {|o| return o unless o.nil? or o.empty?} exit_now!("Error: --#{name.to_s} is required") end |
#view_to_print(global, fields, print_options = nil) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/mc/helper.rb', line 45 def view_to_print(global, fields, =nil) if global[:raw] # only show the first field and nothing else return fields.first, {:show_index => false} else return fields, end end |