class QiitaGetTemplate

Public Class Methods

new(os, filename) click to toggle source
# File lib/qiita_org/get_template.rb, line 7
def initialize(os, filename)
  @os = os
  @filename = filename
  @conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
end

Public Instance Methods

check_write_contents() click to toggle source
# File lib/qiita_org/get_template.rb, line 74
def check_write_contents()
  if @os == "mac"
    ["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
  elsif @os == "windows"
    ["Ubuntu", "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
  else
    ["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
end
cp_template() click to toggle source

cp template.org

# File lib/qiita_org/get_template.rb, line 62
def cp_template()
  lib = File.expand_path("../../../lib", __FILE__)
  cp_file = File.join(lib, "qiita_org", "template.org")

  if File.exists?("./#{@filename}")
    puts "#{@filename} exists.".red
    exit
  else
    FileUtils.cp(cp_file, @filename, verbose: true)
  end
end
get_macos_version() click to toggle source
# File lib/qiita_org/get_template.rb, line 13
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(@filename)
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1].gsub(" ", "")}-#{m[2]}-brightgreen) "
  File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
end
get_ruby_version() click to toggle source
# File lib/qiita_org/get_template.rb, line 50
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(@filename)
  conts << "![ruby-#{m[1]}](https://img.shields.io/badge/ruby-#{m[1].gsub(" ", "")}-brightgreen) "
  File.write(@filename, conts) # + "ruby: # {m[1]}\n")
end
get_ubuntu_version() click to toggle source
# File lib/qiita_org/get_template.rb, line 39
def get_ubuntu_version()
  system 'cat /etc/issue > hoge.txt'
  version = File.read("hoge.txt")
  m = []
  m = version.match(/(.+) (.+) LTS /)
  system 'rm hoge.txt'
  conts = File.read(@filename)
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1]}-#{m[2]}-brightgreen) "
  File.write(@filename, conts)
end
get_windowsos_version() click to toggle source
# File lib/qiita_org/get_template.rb, line 24
def get_windowsos_version()
  system 'wmic.exe os get caption > hoge1.txt'
  system 'wmic.exe os get osarchitecture > hoge2.txt'
  version1 = Kconv.tosjis(File.read("hoge1.txt"))
  version2 = Kconv.tosjis(File.read("hoge2.txt"))
  m1, m2 = [], []
  m1 = version1.match(/Caption\nMicrosoft (.+) (.+)/)
  m2 = version2.match(/OSArchitecture\n(.+)-bit/)
  system 'rm hoge1.txt'
  system 'rm hoge2.txt'
  conts = File.read(@filename)
  conts << "![#{m1[1]}-#{m1[2]}](https://img.shields.io/badge/#{m1[1].gsub(" ", "")}#{m1[2]}-#{m2[1]}bit-brightgreen) "
  File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
end
run() click to toggle source
# File lib/qiita_org/get_template.rb, line 116
def run()
  ErrorMessage.new().config_set_error(@conf_dir)
  cp_template()
  set_name_and_email()
  check_write_contents()
end
set_name_and_email() click to toggle source
# File lib/qiita_org/get_template.rb, line 105
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(@filename)
  conts[3] = "#+AUTHOR: #{name}\n"
  conts[4] = "#+EMAIL:     (concat \"#{email}\")\n"
  File.write(@filename, conts.join)
end