Module: WpUsers::Output

Included in:
WpUsers
Defined in:
lib/common/collections/wp_users/output.rb

Instance Method Summary collapse

Instance Method Details

#output(options = {}) ⇒ void

This method returns an undefined value.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/common/collections/wp_users/output.rb', line 10

def output(options = {})
  rows     = []
  headings = ['Id', 'Login', 'Name']
  headings << 'Password' if options[:show_password]

  remove_junk_from_display_names

  self.each do |wp_user|
    row = [wp_user.id, wp_user., wp_user.display_name]
    row << wp_user.password if options[:show_password]
    rows << row
  end

  table = Terminal::Table.new(headings: headings,
                              rows: rows,
                              style: { margin_left: options[:margin_left] || '' }).to_s
  # variable needed for output
  puts table
end

#remove_junk_from_display_namesObject


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/common/collections/wp_users/output.rb', line 30

def remove_junk_from_display_names
  display_names = []
  self.each do |u|
    display_name = u.display_name
    unless display_name == 'empty'
      display_names << display_name
    end
  end
  junk = get_equal_string_end(display_names)
  unless junk.nil? or junk.empty?
    self.each do |u|
      u.display_name ||= ''
      u.display_name = u.display_name.sub(/#{Regexp.escape(junk)}$/, '')
    end
  end
end