Class: Project

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/asker/project.rb

Overview

Contains Project data and methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProject

Initialize



15
16
17
# File 'lib/asker/project.rb', line 15

def initialize
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args, &_block) ⇒ Object



116
117
118
# File 'lib/asker/project.rb', line 116

def method_missing(method, *_args, &_block)
  get(method)
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



11
12
13
# File 'lib/asker/project.rb', line 11

def default
  @default
end

#paramObject (readonly)

Returns the value of attribute param.



11
12
13
# File 'lib/asker/project.rb', line 11

def param
  @param
end

Instance Method Details

#closeObject

Close output files



96
97
98
99
100
101
# File 'lib/asker/project.rb', line 96

def close
  get(:logfile).close
  get(:outputfile).close
  get(:lessonfile).close
  get(:yamlfile).close
end

#get(key) ⇒ Object

Get value param

Parameters:

  • key (Symbol)

    key



39
40
41
42
43
# File 'lib/asker/project.rb', line 39

def get(key)
  return @param[key] unless @param[key].nil?

  @default[key]
end

#openObject

Open new project

  • setting new params and

  • creating output files

IMPORTANT: We need at least theses values

  • process_file

  • inputdirs



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/asker/project.rb', line 60

def open
  ext = '.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[:logname] ||
                     "#{@param[:projectname]}-log.txt"
  @param[:outputname] = @param[:outputname] ||
                        "#{@param[:projectname]}-gift.txt"
  @param[:lessonname] = @param[:lessonname] ||
                        "#{@param[:projectname]}-doc.txt"
  @param[:yamlname] = @param[:yamlname] ||
                      "#{@param[:projectname]}.yaml"

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

  Dir.mkdir(get(:outputdir)) unless Dir.exist?(get(:outputdir))
  create_log_file
  create_output_file
  create_lesson_file
  create_yaml_file
end

#resetObject

Reset project params



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/asker/project.rb', line 21

def reset
  @default = { inputbasedir: FileUtils.pwd,
              outputdir: 'output',
              category: :none,
              formula_weights: [1, 1, 1],
              lang: 'en',
              locales: %w[en es javascript math python ruby sql],
              show_mode: :default,
              verbose: true,
              stages: { d: true, b: true, f: true, i: true, s: true, t: true },
              threshold: 0.5,
              color_output: true }
  @param = {}
end

#set(key, value) ⇒ Object

Set value param

Parameters:

  • key (Symbol)

    key

  • value (String)

    value



49
50
51
# File 'lib/asker/project.rb', line 49

def set(key, value)
  @param[key] = value
end

#verbose(msg) ⇒ Object

Display and log text



105
106
107
108
# File 'lib/asker/project.rb', line 105

def verbose(msg)
  puts msg if get(:verbose)
  get(:logfile).write(msg.to_s + "\n") if get(:logfile)
end

#verboseln(msg) ⇒ Object

Display and log text line



112
113
114
# File 'lib/asker/project.rb', line 112

def verboseln(msg)
  verbose(msg + "\n")
end