Class: QiitaGetTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita_org/get_template.rb

Instance Method Summary collapse

Constructor Details

#initializeQiitaGetTemplate

Returns a new instance of QiitaGetTemplate.



5
6
7
8
9
10
# File 'lib/qiita_org/get_template.rb', line 5

def initialize()
  cp_template()
  set_name_and_email()
  # check_write_header()
  check_write_contents()
end

Instance Method Details

#check_write_contentsObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/qiita_org/get_template.rb', line 47

def check_write_contents()
  ["MacOS", "ruby"].each do |src|
    print "Write #{src} version?(y/n) "
    ans = STDIN.gets.chomp
    next if ans == "n"
    if ans == "y"
      send("get_#{src.downcase}_version")
    end
  end
end

#check_write_headerObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/qiita_org/get_template.rb', line 58

def check_write_header()
  ["name", "email"].each do |src|
    print "Write your #{src}?(y/n) "
    ans = STDIN.gets.chomp
    next if ans == "n"
    if ans == "y"
      send("get_#{src}")
    end
  end
end

#cp_templateObject

cp template.org



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/qiita_org/get_template.rb', line 35

def cp_template()
  lib = File.expand_path("../../../lib", __FILE__)
  cp_file = File.join(lib, "qiita_org", "template.org")

  if File.exists?("./template.org")
    puts "template.org exists.".red
    exit
  else
    FileUtils.cp(cp_file, ".", verbose: true)
  end
end

#get_emailObject



77
78
79
80
81
82
83
# File 'lib/qiita_org/get_template.rb', line 77

def get_email()
  conts = File.readlines("template.org")
  p "Type your email"
  email = STDIN.gets
  conts[4] = "#+EMAIL:     (concat \"#{email.chomp}\")\n"
  File.write("template.org", conts.join)
end

#get_macos_versionObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/qiita_org/get_template.rb', line 12

def get_macos_version()
  system 'sw_vers > hoge.txt'
  version = File.read("hoge.txt")
  m = []
  m = version.match(/ProductName:\t(.+)\nProductVersion:\t(.+)\nBuildVersion:\t(.+)\n/)
  system 'rm hoge.txt'
  conts = File.read("template.org")
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1].gsub(" ", "")}-#{m[2]}-brightgreen) "
  File.write("template.org", conts) # + "# {m[1]}: # {m[2]}\n")
end

#get_nameObject



69
70
71
72
73
74
75
# File 'lib/qiita_org/get_template.rb', line 69

def get_name()
  conts = File.readlines("template.org")
  p "Type your name"
  name = STDIN.gets
  conts[3] = "#+AUTHOR: #{name}"
  File.write("template.org", conts.join)
end

#get_ruby_versionObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/qiita_org/get_template.rb', line 23

def get_ruby_version()
  system 'ruby --version > hoge.txt'
  version = File.read("hoge.txt")
  m = []
  m = version.match(/ruby (.+) \((.+)/)
  system 'rm hoge.txt'
  conts = File.read("template.org")
  conts << "![ruby-#{m[1]}](https://img.shields.io/badge/ruby-#{m[1].gsub(" ", "")}-brightgreen) "
  File.write("template.org", conts) # + "ruby: # {m[1]}\n")
end

#set_name_and_emailObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/qiita_org/get_template.rb', line 85

def set_name_and_email()
  conf_path = File.join(ENV["HOME"], ".qiita.conf")
  conf = JSON.load(File.read(conf_path))
  name = conf["name"]
  email = conf["email"]
  conts = File.readlines("template.org")
  conts[3] = "#+AUTHOR: #{name}\n"
  conts[4] = "#+EMAIL:     (concat \"#{email}\")\n"
  File.write("template.org", conts.join)
end