class Project

Contains Project data and methods

Attributes

default[R]
param[R]

Public Class Methods

new() click to toggle source

Initialize

# File lib/asker/project.rb, line 16
def initialize
  reset
end

Public Instance Methods

close() click to toggle source

Close output files

# File lib/asker/project.rb, line 83
def close
  get(:logfile).close
  get(:outputfile).close
  get(:lessonfile).close
  get(:yamlfile).close
end
get(key) click to toggle source

Get value param @param key (Symbol) key

# File lib/asker/project.rb, line 32
def get(key)
  return @param[key] unless @param[key].nil?

  @default[key]
end
method_missing(method, *_args, &_block) click to toggle source
# File lib/asker/project.rb, line 90
def method_missing(method, *_args, &_block)
  get(method)
end
open() click to toggle source

Open new project

  • setting new params and

  • creating output files

IMPORTANT: We need at least theses values

  • process_file

  • inputdirs

# File lib/asker/project.rb, line 53
def open
  config = Application.instance.config
  ext = File.extname(@param[:process_file]) || '.haml'
  #@param[:process_file] = @param[:process_file] ||
  #                        get(:projectdir).split(File::SEPARATOR).last + ext
  @param[:projectname] = @param[:projectname] ||
                         File.basename(@param[:process_file], ext)
  #@param[:inputdirs] = @param[:inputdirs] ||
  #                     File.join(get(:inputbasedir), @param[:projectdir])

  @param[:logname] = "#{@param[:projectname]}-log.txt"
  @param[:outputname] = "#{@param[:projectname]}-gift.txt"
  @param[:lessonname] = "#{@param[:projectname]}-doc.txt"
  @param[:yamlname] = "#{@param[:projectname]}.yaml"

  outputdir = config['global']['outputdir']
  @param[:logpath] = File.join(outputdir, get(:logname))
  @param[:outputpath] = File.join(outputdir, get(:outputname))
  @param[:lessonpath] = File.join(outputdir, get(:lessonname))
  @param[:yamlpath] = File.join(outputdir, get(:yamlname))

  Dir.mkdir(outputdir) unless Dir.exist?(outputdir)
  create_log_file
  create_output_file
  create_lesson_file
  create_yaml_file
end
reset() click to toggle source

Reset project params

# File lib/asker/project.rb, line 22
def reset
  @default = { inputbasedir: FileUtils.pwd,
              stages: { d: true, b: true, f: true, i: true, s: true, t: true },
              threshold: 0.5 }
  @param = {}
end
set(key, value) click to toggle source

Set value param @param key (Symbol) key @param value (String) value

# File lib/asker/project.rb, line 42
def set(key, value)
  @param[key] = value
end

Private Instance Methods

create_lesson_file() click to toggle source

Create or reset lesson file

# File lib/asker/project.rb, line 130
def create_lesson_file
  @param[:lessonfile] = File.new(get(:lessonpath), 'w')
  f = get(:lessonfile)
  f.write('=' * 50 + "\n")
  f.write("Created by : #{Application::NAME}")
  f.write(" (version #{Application::VERSION})\n")
  f.write("File       : #{get(:lessonname)}\n")
  f.write("Time       : #{Time.new}\n")
  f.write("Author     : David Vargas Ruiz\n")
  f.write('=' * 50 + "\n")
end
create_log_file() click to toggle source

create or reset logfile

# File lib/asker/project.rb, line 97
def create_log_file
  @param[:logfile] = File.open(get(:logpath), 'w')
  f = get(:logfile)
  f.write('=' * 50 + "\n")
  f.write("Created by : #{Application::NAME}")
  f.write(" (version #{Application::VERSION})\n")
  f.write("File       : #{get(:logname)}\n")
  f.write("Time       : #{Time.new}\n")
  f.write("Author     : David Vargas Ruiz\n")
  f.write('=' * 50 + "\n\n")

  Logger.verbose '[INFO] Project open'
  Logger.verbose '   ├── inputdirs    = ' + Rainbow(get(:inputdirs)).bright
  Logger.verbose '   └── process_file = ' + Rainbow(get(:process_file)).bright
end
create_output_file() click to toggle source

Create or reset output file

# File lib/asker/project.rb, line 114
def create_output_file
  config = Application.instance.config
  @param[:outputfile] = File.open(get(:outputpath), 'w')
  f = get(:outputfile)
  f.write('// ' + ('=' * 50) + "\n")
  f.write("// Created by : #{Application::NAME}")
  f.write(" (version #{Application::VERSION})\n")
  f.write("// File       : #{get(:outputname)}\n")
  f.write("// Time       : #{Time.new}\n")
  f.write("// Author     : David Vargas Ruiz\n")
  f.write('// ' + ('=' * 50) + "\n\n")
  category = config['questions']['category']
  f.write("$CATEGORY: $course$/#{category}\n") unless category.nil?
end
create_yaml_file() click to toggle source

Create or reset yaml file

# File lib/asker/project.rb, line 143
def create_yaml_file
  @param[:yamlfile] = File.open(get(:yamlpath), 'w')
end