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.



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

def initialize()
  cp_template()
  search = SearchConfPath.new(Dir.pwd, Dir.home)
  @conf_dir = search.search_conf_path()
  set_name_and_email()
  # check_write_header()
  check_write_contents()
end

Instance Method Details

#check_write_contentsObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/qiita_org/get_template.rb', line 50

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



61
62
63
64
65
66
67
68
69
70
# File 'lib/qiita_org/get_template.rb', line 61

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



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/qiita_org/get_template.rb', line 38

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



80
81
82
83
84
85
86
# File 'lib/qiita_org/get_template.rb', line 80

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



15
16
17
18
19
20
21
22
23
24
# File 'lib/qiita_org/get_template.rb', line 15

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



72
73
74
75
76
77
78
# File 'lib/qiita_org/get_template.rb', line 72

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



26
27
28
29
30
31
32
33
34
35
# File 'lib/qiita_org/get_template.rb', line 26

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



88
89
90
91
92
93
94
95
96
97
# File 'lib/qiita_org/get_template.rb', line 88

def set_name_and_email()
  conf_path = File.join(@conf_dir, ".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