Class: AliyunExmailCSVGenerator::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun_exmail_csv_generator/account.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  workno: nil,
  password: 'Hello1234',
  department: '公司',
  phone_ext: nil,
  title: nil,
  mobile: nil,
  capacity: 2048
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, email, options = DEFAULT_OPTIONS) ⇒ Account

Returns a new instance of Account.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 18

def initialize(name, email, options = DEFAULT_OPTIONS)
  options ||= DEFAULT_OPTIONS
  @name       = name
  @email      = email

  @workno     = options[:workno] || DEFAULT_OPTIONS[:workno]
  @password   = options[:password] || DEFAULT_OPTIONS[:password]
  @department = options[:department] || DEFAULT_OPTIONS[:department]
  @phone_ext  = options[:phone_ext] || DEFAULT_OPTIONS[:phone_ext]
  @title      = options[:title] || DEFAULT_OPTIONS[:title]
  @mobile     = options[:mobile] || DEFAULT_OPTIONS[:mobile]
  @capacity   = options[:capacity] || DEFAULT_OPTIONS[:capacity]
end

Instance Attribute Details

#capacityObject

Returns the value of attribute capacity.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def capacity
  @capacity
end

#departmentObject

Returns the value of attribute department.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def department
  @department
end

#emailObject

Returns the value of attribute email.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def email
  @email
end

#mobileObject

Returns the value of attribute mobile.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def mobile
  @mobile
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def name
  @name
end

#passwordObject

Returns the value of attribute password.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def password
  @password
end

#phone_extObject

Returns the value of attribute phone_ext.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def phone_ext
  @phone_ext
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def title
  @title
end

#worknoObject

Returns the value of attribute workno.



16
17
18
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 16

def workno
  @workno
end

Class Method Details

.from(name_list, options = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 37

def from(name_list, options = nil)
  accounts = []
  name_list.each do |name|
    name_pinyin = name_to_pinyin(name)
    email = "#{name_pinyin}@qcpt.org"
    accounts << .new(name, email, options)
  end
  accounts
end

.name_to_pinyin(name) ⇒ Object



47
48
49
50
51
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 47

def name_to_pinyin(name)
  name_pinyin = PinYin.of_string(name)
  name_pinyin = name_pinyin.push('.').rotate! if name_pinyin.length > 1
  name_pinyin.map(&:downcase).join
end

Instance Method Details

#to_csv_rowObject



32
33
34
# File 'lib/aliyun_exmail_csv_generator/account.rb', line 32

def to_csv_row
  [@name, @email, @workno, @password, @department, @phone_ext, @title, @mobile, @capacity]
end