Skip to content

Instantly share code, notes, and snippets.

@yoxisem544
Created June 11, 2016 05:21
Show Gist options
  • Save yoxisem544/5927e517d3c0eff93322c5b9d5682ce6 to your computer and use it in GitHub Desktop.
Save yoxisem544/5927e517d3c0eff93322c5b9d5682ce6 to your computer and use it in GitHub Desktop.
require 'json'
require "pp"
require 'csv'
file = File.read('./PersonalInformation.json')
data_hash = JSON.parse(file)
if data_hash
pp("json has data")
end
temp_csv_data = []
data_hash["results"].each do |data|
a = [
data["userUUID"],
# Basic information
data["userName"],
data["userPhone"],
data["userEMAIL"],
data["userCompany"],
data["userDepartment"],
# First part
data["sex"],
data["age"],
data["educationalBackground"],
data["serviceTimeLength"],
data["currentRank"],
data["currentDepartmentProperty"],
data["currentCompanyProperty"],
# Second part
data["directManagerSex"],
data["peopleThatDirectManagerManaged"],
data["timeSpentWithDirectManager"],
# 1. Authoritarian leadership (Cheng et al., 2014)
data["authoritarianLeadershipQuestion1"],
data["authoritarianLeadershipQuestion2"],
data["authoritarianLeadershipQuestion3"],
data["authoritarianLeadershipQuestion4"],
data["authoritarianLeadershipQuestion5"],
# 2. Benevolent leadership (Cheng et al., 2014)
data["benevolentLeadershipQuestion1"],
data["benevolentLeadershipQuestion2"],
data["benevolentLeadershipQuestion3"],
data["benevolentLeadershipQuestion4"],
data["benevolentLeadershipQuestion5"],
# 3. Person-life inclusion (Chen, Friedman, Yu, Fang, & Lu, 2009)
data["personLifeInclusionQuestion1"],
data["personLifeInclusionQuestion2"],
data["personLifeInclusionQuestion3"],
data["personLifeInclusionQuestion4"],
# 4. Deference to supervisor (Chen et al., 2009)
data["deferenceToSupervisorQuestion1"],
data["deferenceToSupervisorQuestion2"],
data["deferenceToSupervisorQuestion3"],
data["deferenceToSupervisorQuestion4"],
# 5. General supervisor-directed OCB
data["generalSupervisorDirectedOCBQuestion1"],
data["generalSupervisorDirectedOCBQuestion2"],
data["generalSupervisorDirectedOCBQuestion3"],
data["generalSupervisorDirectedOCBQuestion4"],
# 6. Perceived supervisor effectiveness (Denison, Hoojiberg, & Quinn, 1995)
data["perceivedSupervisorEffectivenessQuestion1"],
data["perceivedSupervisorEffectivenessQuestion2"],
data["perceivedSupervisorEffectivenessQuestion3"],
data["perceivedSupervisorEffectivenessQuestion4"],
# Third part
# 7. Intensity of supervisor-subordinate interaction (與主管互動形式的頻率高低)
data["intensityOfSupervisorSubordinateInteractionQuestion1"],
data["intensityOfSupervisorSubordinateInteractionQuestion2"],
data["intensityOfSupervisorSubordinateInteractionQuestion3"],
data["intensityOfSupervisorSubordinateInteractionQuestion4"],
data["intensityOfSupervisorSubordinateInteractionQuestion5"],
# Fourth part
# 8. Trait job satisfaction (Ilies, Wilson, & Wagner, 2009) [根據目前工作經驗填答]
data["traitJobSatisfactionQuestion1"],
data["traitJobSatisfactionQuestion2"],
data["traitJobSatisfactionQuestion3"],
data["traitJobSatisfactionQuestion4"],
data["traitJobSatisfactionQuestion5"],
# 9. Competence (Spreitzer, 1995)
data["competenceQuestion1"],
data["competenceQuestion2"],
data["competenceQuestion3"],
# Fifth part
# 10. Quantitative job demand (workload) (Schaufeli & Bakker, 2004)
data["quantitativeJobDemandQuestion1"],
data["quantitativeJobDemandQuestion2"],
data["quantitativeJobDemandQuestion3"],
data["quantitativeJobDemandQuestion4"],
data["quantitativeJobDemandQuestion5"],
# 11. Emotional job demand (Schaufeli & Bakker, 2004))
data["emotionalJobDemandQuestion1"],
data["emotionalJobDemandQuestion2"],
data["emotionalJobDemandQuestion3"],
data["emotionalJobDemandQuestion4"],
data["emotionalJobDemandQuestion5"],
# Sixth part
# 12. Power distance orientation (Dorfman & Howell, 1988)
data["powerDistanceOrientationQuestion1"],
data["powerDistanceOrientationQuestion2"],
data["powerDistanceOrientationQuestion3"],
data["powerDistanceOrientationQuestion4"],
data["powerDistanceOrientationQuestion5"],
data["powerDistanceOrientationQuestion6"],
# 13. Chastening norm orientation (修改自王中豫, 2013)
data["chasteningNormOrientationQuestion1"],
data["chasteningNormOrientationQuestion2"],
data["chasteningNormOrientationQuestion3"],
data["chasteningNormOrientationQuestion4"],
data["chasteningNormOrientationQuestion5"],
data["chasteningNormOrientationQuestion6"],
data["chasteningNormOrientationQuestion7"]
]
temp_csv_data << a
end
CSV.open("personalInfo.csv", "w") do |csv|
temp_csv_data.each do |data|
csv << data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment