Class: Githug::Level
Constant Summary collapse
- LEVELS =
[nil, "init", "config", "add", "commit", "clone", "clone_to_folder", "ignore", "include", "status", "number_of_files_committed", "rm", "rm_cached", "stash", "rename", "restructure", "log", "tag", "push_tags", "commit_amend", "commit_in_future", "reset", "reset_soft", "checkout_file", "remote", "remote_url", "pull", "remote_add", "push", "diff", "blame", "branch", "checkout", "checkout_tag", "checkout_tag_over_branch", "branch_at", "delete_branch", "push_branch", "merge", "fetch", "rebase", "rebase_onto", "repack", "cherry-pick", "grep", "rename_commit", "squash", "merge_squash", "reorder", "bisect", "stage_lines", "find_old_branch", "revert", "restore", "conflict", "submodule","contribute"]
Instance Attribute Summary collapse
-
#level_name ⇒ Object
Returns the value of attribute level_name.
-
#level_no ⇒ Object
Returns the value of attribute level_no.
-
#level_path ⇒ Object
Returns the value of attribute level_path.
Class Method Summary collapse
Instance Method Summary collapse
- #description(description) ⇒ Object
- #difficulty(num) ⇒ Object
- #full_description ⇒ Object
- #hint(&hint) ⇒ Object
- #hints(hints) ⇒ Object
- #init_from_level ⇒ Object
- #repo(location = "") ⇒ Object
- #setup(&block) ⇒ Object
- #setup_level ⇒ Object
- #show_hint ⇒ Object
- #solution(&block) ⇒ Object
- #solve ⇒ Object
- #test ⇒ Object
Methods included from UI
ask, colorize, error, gets, #method_missing, print, puts, request, success, word_box
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Githug::UI
Instance Attribute Details
#level_name ⇒ Object
Returns the value of attribute level_name.
17 18 19 |
# File 'lib/githug/level.rb', line 17 def level_name @level_name end |
#level_no ⇒ Object
Returns the value of attribute level_no.
17 18 19 |
# File 'lib/githug/level.rb', line 17 def level_no @level_no end |
#level_path ⇒ Object
Returns the value of attribute level_path.
17 18 19 |
# File 'lib/githug/level.rb', line 17 def level_path @level_path end |
Class Method Details
.list ⇒ Object
30 31 32 |
# File 'lib/githug/level.rb', line 30 def list return LEVELS - [nil] end |
.load(level_name) ⇒ Object
21 22 23 24 |
# File 'lib/githug/level.rb', line 21 def load(level_name) path = "#{File.dirname(__FILE__)}/../../levels/#{level_name}.rb" setup(path) end |
.load_from_file(path) ⇒ Object
26 27 28 |
# File 'lib/githug/level.rb', line 26 def load_from_file(path) setup(path) end |
.setup(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/githug/level.rb', line 34 def setup(path) level_path = path.chomp(File.extname(path)) level = self.new return false unless File.exists?(path) level.instance_eval(File.read(path)) level.level_name = File.basename(path, File.extname(path)) level.level_no = LEVELS.index(level.level_name) || 1 level.level_path = level_path level end |
Instance Method Details
#description(description) ⇒ Object
58 59 60 |
# File 'lib/githug/level.rb', line 58 def description(description) @description = description end |
#difficulty(num) ⇒ Object
54 55 56 |
# File 'lib/githug/level.rb', line 54 def difficulty(num) @difficulty = num end |
#full_description ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/githug/level.rb', line 79 def full_description UI.puts UI.puts "Name: #{level_name}" UI.puts "Level: #{level_no}" UI.puts "Difficulty: #{"*"*@difficulty}" UI.puts UI.puts @description UI.puts end |
#hint(&hint) ⇒ Object
71 72 73 |
# File 'lib/githug/level.rb', line 71 def hint(&hint) @hint = hint end |
#hints(hints) ⇒ Object
75 76 77 |
# File 'lib/githug/level.rb', line 75 def hints(hints) @hints = hints end |
#init_from_level ⇒ Object
49 50 51 52 |
# File 'lib/githug/level.rb', line 49 def init_from_level FileUtils.cp_r("#{level_path}/.", ".") FileUtils.mv(".githug", ".git") end |
#repo(location = "") ⇒ Object
94 95 96 |
# File 'lib/githug/level.rb', line 94 def repo(location = "") @repo ||= Repository.new(location) end |
#setup(&block) ⇒ Object
67 68 69 |
# File 'lib/githug/level.rb', line 67 def setup(&block) @setup = block end |
#setup_level ⇒ Object
89 90 91 92 |
# File 'lib/githug/level.rb', line 89 def setup_level repo.reset @setup.call if @setup end |
#show_hint ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/githug/level.rb', line 108 def show_hint UI.word_box("Githug") profile = Profile.load current_hint_index = profile.current_hint_index if @hints puts @hints[current_hint_index] if current_hint_index < @hints.size - 1 profile.current_hint_index += 1 profile.save else profile.current_hint_index = 0 profile.save end elsif @hint @hint.call else UI.puts("No hints available for this level.") end end |
#solution(&block) ⇒ Object
62 63 64 65 |
# File 'lib/githug/level.rb', line 62 def solution(&block) singleton = class << self; self end singleton.send :define_method, :_solution, &block end |
#solve ⇒ Object
98 99 100 101 102 |
# File 'lib/githug/level.rb', line 98 def solve _solution rescue false end |
#test ⇒ Object
104 105 106 |
# File 'lib/githug/level.rb', line 104 def test _solution end |