Class: Faker::CompanyData

Inherits:
Object
  • Object
show all
Defined in:
lib/faker/company_data.rb,
lib/faker/company_data_image.rb

Class Method Summary collapse

Class Method Details

.cost_centerObject



40
41
42
# File 'lib/faker/company_data.rb', line 40

def cost_center
  cost_center_all.sample
end

.cost_center_allObject



43
44
45
# File 'lib/faker/company_data.rb', line 43

def cost_center_all
  json_file_hash["cost_centers"]
end

.departmentObject



10
11
12
# File 'lib/faker/company_data.rb', line 10

def department
  department_all.sample
end

.department_allObject



13
14
15
# File 'lib/faker/company_data.rb', line 13

def department_all
  json_file_hash["departments"].map{ |i| i["name"] }
end

.group(department = nil) ⇒ Object



28
29
30
# File 'lib/faker/company_data.rb', line 28

def group(department = nil)
  group_all(department).sample
end

.group_all(department = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/faker/company_data.rb', line 31

def group_all(department = nil)
  groups_default = json_file_hash["groups"]
  if department
    groups = json_file_hash["departments"].select{ |k,v| k["name"] == department }.map{ |i| i["groups"] }.flatten(1)
  else
    groups = json_file_hash["departments"].map{ |i| i["groups"] }.flatten(1)
  end
  groups_default.concat(groups).compact
end

.job_title(department = nil, team = nil) ⇒ Object



46
47
48
# File 'lib/faker/company_data.rb', line 46

def job_title(department = nil, team = nil)
  job_title_all(department, team).sample
end

.job_title_all(department = nil, team = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/faker/company_data.rb', line 49

def job_title_all(department = nil, team = nil)
  job_titles_default = json_file_hash["job_titles"]

  if department
    department_hash = json_file_hash["departments"].select{ |k,v| k["name"] == department }
    job_titles_department_default = department_hash.map{ |i| i["job_titles"] }.flatten(1)

    job_titles_default_with_department_default = job_titles_default.concat(job_titles_department_default).compact

    teams = department_hash.map{ |i| i["teams"] }.flatten(1)

    if team
      teams_job_titles = teams.select{ |k,v| k["name"] == team }.map{ |i| i["job_titles"] }.flatten(1)
    else
      teams_job_titles = teams.map{ |i| i["job_titles"] }.flatten(1)
    end

    job_titles_default_with_department_default.concat(teams_job_titles).compact
  else
    job_titles_departments_default = json_file_hash["departments"].map{ |i| i["job_titles"] }.flatten(1)
    job_titles_default_with_departments_default = job_titles_default.concat(job_titles_departments_default).compact

    teams = json_file_hash["departments"].map{ |i| i["teams"] }.flatten(1)
    teams_job_titles = teams.map{ |i| i["job_titles"] }.flatten(1)

    job_titles_default_with_departments_default.concat(teams_job_titles).compact
  end
end

.profile_image(gender) ⇒ Object



14
15
16
# File 'lib/faker/company_data_image.rb', line 14

def profile_image(gender)
  profile_image_all(gender).sample
end

.profile_image_all(gender) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/faker/company_data_image.rb', line 18

def profile_image_all(gender)
  if gender == 'female' || gender == :female
    Dir["#{profile_image_path}female/*"]
  else
    Dir["#{profile_image_path}male/*"]
  end
end

.shiftObject



4
5
6
# File 'lib/faker/company_data.rb', line 4

def shift
  shift_all.sample
end

.shift_allObject



7
8
9
# File 'lib/faker/company_data.rb', line 7

def shift_all
  json_file_hash["shifts"]
end

.team(department = nil) ⇒ Object



16
17
18
# File 'lib/faker/company_data.rb', line 16

def team(department = nil)
  team_all(department).sample
end

.team_all(department = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/faker/company_data.rb', line 19

def team_all(department = nil)
  teams_default = json_file_hash["teams"].flatten(1).map { |i| i["name"] }
  if department
    teams = json_file_hash["departments"].select{ |k,v| k["name"] == department }.map{ |i| i["teams"] }.flatten(1).map { |i| i["name"] }
  else
    teams = json_file_hash["departments"].map{ |i| i["teams"] }.flatten(1).map { |i| i["name"] }
  end
  teams_default.concat(teams).compact
end

.team_image(name) ⇒ Object



6
7
8
# File 'lib/faker/company_data_image.rb', line 6

def team_image(name)
  "#{team_image_path}#{I18n.transliterate(name.downcase).gsub(/[^0-9A-Za-z ]/,'').gsub(" ", "_")}.jpg"
end

.team_image_allObject



10
11
12
# File 'lib/faker/company_data_image.rb', line 10

def team_image_all
  Dir["#{team_image_path}*"]
end