Class: WhoToWho::ParseArgs

Inherits:
Object
  • Object
show all
Defined in:
lib/whotowho/parseargs.rb

Overview

Class for parse Args and save all into

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/whotowho/parseargs.rb', line 9

def content
  @content
end

#fromObject (readonly)

Returns the value of attribute from.



10
11
12
# File 'lib/whotowho/parseargs.rb', line 10

def from
  @from
end

#subjectObject (readonly)

Returns the value of attribute subject.



8
9
10
# File 'lib/whotowho/parseargs.rb', line 8

def subject
  @subject
end

Instance Method Details

#insert(link) ⇒ Object



59
60
61
# File 'lib/whotowho/parseargs.rb', line 59

def insert(link)
  @list_link << link
end

#parse(args, prog) ⇒ Object

Parse all argument and check if required is define



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/whotowho/parseargs.rb', line 13

def parse(args, prog)
  WhoToWho.log.level = Logger::INFO
  options = OptionParser.new do |opts|
    
    opts.banner = "Usage: #{prog} [options]"
    
    opts.on("-v", "--verbose", "Run verbosely") do |v|
      WhoToWho.log.level = Logger::DEBUG
      WhoToWho.log.debug "Debug Activate"
    end
    opts.on( '-f', '--file REQUIRED', :REQUIRED, 'File where is all data') do |f|
      load_file f
    end
    opts.on('-c', '--config FILE', :REQUIRED, 'File where is all config') do |f|
      load_config f
    end
    opts.on('-g', '--gmail', 'Define option if use a Gmail account for SMTP') do |g|
      require_dependency('whotowho/smtp_tls') if g
    end
    opts.on('-s', '--subject SUBJECT', :REQUIRED, 'Define the subject to send by email') do |s|
      @subject = s
    end
    opts.on('-m FILE', '--mail MAIL', :REQUIRED, 'Send a file where the content is with 2 params #{who} and #{towho}') do |c|
      @content = File.open(c).read
    end

    @full_print = opts

  end.parse!
  test_required
  @test = 0
end

#put_randomObject

Send a random Link objet from list_link save into



48
49
50
51
# File 'lib/whotowho/parseargs.rb', line 48

def put_random
  rand_index = rand(@list_link.size)
  @list_link.slice!(rand_index)
end

#refreshObject



68
69
70
71
72
73
74
75
76
# File 'lib/whotowho/parseargs.rb', line 68

def refresh
  @list_link = Array.new @list_link_copy
  WhoToWho.log.debug 'refresh'
  @test += 1
  if @test > 3
    WhoToWho.log.warn 'Sorry this combinaison is hard to randomise, please report your data file in bugtracking http://rubyforge.org/tracker/?group_id=4883'
    exit
  end
end

#sizeObject

Size of list_link in args



54
55
56
# File 'lib/whotowho/parseargs.rb', line 54

def size
  @list_link.size
end