belajar 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -4
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/Gemfile +1 -1
  5. data/README.md +76 -1
  6. data/Rakefile +1 -1
  7. data/belajar.gemspec +23 -26
  8. data/belajar.png +0 -0
  9. data/bin/belajar +6 -2
  10. data/lib/belajar.rb +0 -1
  11. data/lib/belajar/chapter.rb +3 -4
  12. data/lib/belajar/coloring.rb +32 -0
  13. data/lib/belajar/configuration.rb +25 -28
  14. data/lib/belajar/congratulator.rb +17 -5
  15. data/lib/belajar/course.rb +9 -8
  16. data/lib/belajar/exceptions.rb +0 -2
  17. data/lib/belajar/generator.rb +13 -15
  18. data/lib/belajar/github_client.rb +5 -5
  19. data/lib/belajar/loadable.rb +23 -14
  20. data/lib/belajar/loading/chapters.rb +0 -2
  21. data/lib/belajar/loading/courses.rb +0 -2
  22. data/lib/belajar/loading/units.rb +0 -2
  23. data/lib/belajar/markdown.rb +2 -0
  24. data/lib/belajar/markdown/printer.rb +89 -0
  25. data/lib/belajar/markdown/ruby_doc.rb +104 -0
  26. data/lib/belajar/solution.rb +23 -15
  27. data/lib/belajar/storeable.rb +11 -12
  28. data/lib/belajar/task.rb +1 -1
  29. data/lib/belajar/terminal.rb +3 -4
  30. data/lib/belajar/terminal/cli.rb +8 -8
  31. data/lib/belajar/terminal/courses.rb +24 -21
  32. data/lib/belajar/terminal/output.rb +46 -53
  33. data/lib/belajar/terminal/setup.rb +13 -18
  34. data/lib/belajar/terminal/solutions.rb +27 -32
  35. data/lib/belajar/terminal/texts/hint_course_download.txt +2 -2
  36. data/lib/belajar/terminal/welcome.rb +9 -11
  37. data/lib/belajar/test.rb +7 -10
  38. data/lib/belajar/test_result.rb +54 -21
  39. data/lib/belajar/unit.rb +2 -4
  40. data/lib/belajar/version.rb +1 -1
  41. data/lib/belajar/views.rb +29 -33
  42. data/lib/belajar/views/chapters_menu.rb +16 -20
  43. data/lib/belajar/views/courses_menu.rb +12 -15
  44. data/lib/belajar/views/main_menu.rb +23 -23
  45. data/lib/belajar/views/menu.rb +14 -18
  46. data/lib/belajar/views/splash.rb +11 -13
  47. data/lib/belajar/views/subscriber.rb +38 -0
  48. data/lib/belajar/views/task_view.rb +97 -80
  49. data/lib/belajar/views/top_bar.rb +4 -10
  50. data/lib/belajar/views/units_menu.rb +16 -21
  51. data/lib/belajar/window.rb +20 -140
  52. data/spec/belajar/chapter_spec.rb +23 -18
  53. data/spec/belajar/coloring_spec.rb +35 -0
  54. data/spec/belajar/configuration_spec.rb +55 -51
  55. data/spec/belajar/congratulator_spec.rb +11 -8
  56. data/spec/belajar/course_spec.rb +75 -52
  57. data/spec/belajar/generator_spec.rb +24 -25
  58. data/spec/belajar/github_client_spec.rb +17 -18
  59. data/spec/belajar/loading/chapters_spec.rb +2 -3
  60. data/spec/belajar/loading/courses_spec.rb +2 -3
  61. data/spec/belajar/loading/units_spec.rb +4 -5
  62. data/spec/belajar/markdown/ruby_doc_spec.rb +116 -0
  63. data/spec/belajar/reference_solution_spec.rb +8 -10
  64. data/spec/belajar/solution_spec.rb +21 -22
  65. data/spec/belajar/storeable_spec.rb +12 -10
  66. data/spec/belajar/task_spec.rb +3 -4
  67. data/spec/belajar/terminal/cli_spec.rb +29 -21
  68. data/spec/belajar/terminal/courses_spec.rb +104 -99
  69. data/spec/belajar/terminal/output_spec.rb +44 -39
  70. data/spec/belajar/terminal/setup_spec.rb +1 -3
  71. data/spec/belajar/terminal/solutions_spec.rb +0 -2
  72. data/spec/belajar/terminal/welcome_spec.rb +0 -2
  73. data/spec/belajar/terminal_spec.rb +5 -7
  74. data/spec/belajar/test_example_spec.rb +16 -14
  75. data/spec/belajar/test_result_spec.rb +21 -25
  76. data/spec/belajar/test_spec.rb +11 -12
  77. data/spec/belajar/unit_spec.rb +24 -27
  78. data/spec/belajar/views/chapters_menu_spec.rb +0 -1
  79. data/spec/belajar/views/courses_menu_spec.rb +0 -1
  80. data/spec/belajar/views/menu_spec.rb +1 -2
  81. data/spec/belajar/views/task_view_spec.rb +0 -2
  82. data/spec/belajar/views/units_menu_spec.rb +0 -1
  83. data/spec/belajar/views_spec.rb +0 -1
  84. data/spec/belajar_spec.rb +9 -12
  85. data/spec/path_helpers_spec.rb +11 -12
  86. data/spec/resource_helpers_spec.rb +11 -12
  87. data/spec/spec_helper.rb +3 -4
  88. data/spec/support/macros/content_helpers.rb +16 -17
  89. data/spec/support/macros/mock_helpers.rb +6 -6
  90. data/spec/support/macros/path_helpers.rb +15 -15
  91. data/spec/support/macros/resource_helpers.rb +34 -35
  92. metadata +56 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ceb199e902cae1cbf1d2fdac248726a72cf77b8e6fc96b358357a50e2adcbb41
4
- data.tar.gz: 1fa6907a4838a2bcfba99975d382635082e58d028164da3c216a1a8ef25214cc
3
+ metadata.gz: bb7c12933b223ccc11cf724aee667cc9f5b772471a89b64076ce15b9aa2312a9
4
+ data.tar.gz: d8ba6686534c17414dfd48084d20a6c5a7b6be01e3ba6cd5d3c2de11ab7d8121
5
5
  SHA512:
6
- metadata.gz: a4db8b51c4ed8bf90fff1c63310e5b2aa61dca71158bffe8754582e46d9530469754cc6b19fd7b743f40fc9d95b941043054c6f96c7f5578f10b6d0303355c3e
7
- data.tar.gz: 071cca5ab34a02d7067ea8b5d9966716bf7f60786d9179ea62a4c17372878a6d0013747be76e436cf0ef26bb7aa55f262ee9ab1d33858dbfe5b6729b6044a082
6
+ metadata.gz: fbcaec9091acca78baf05bb40d7f5d504638dbfda7cbee4a32f2b909a846fd9e5851e68788de64a61900e10b60f6c5ceef52c11834c245ef43cfb728eaad6505
7
+ data.tar.gz: 56a7dbb4676d4906f1523d1ab9ab0e23eb63d5618471e57d6742632740cc892b7b1c1d623c66cabbb2ba1f3308019e8aed410691027d140e9a0a112755be6b46
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
+
3
+ before_install:
4
+ - gem install bundler
5
+
2
6
  rvm:
3
- - 2.0.0
4
- - 2.2.0
5
- - rbx-2
6
- - ruby-head
7
+ - 2.5.0
8
+ - 2.6.0
9
+ - 2.7.0
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at paul.christoph.goetze@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in belajar.gemspec
4
- gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,4 +1,79 @@
1
- # Belajar
1
+ <img src="https://github.com/wong-bejo/belajar/raw/master/belajar.png" width="228" />
2
+
3
+ # belajar
4
+
5
+ _Belajar apa saja melalui terminal, tanpa gangguan iklan dan terlihat lebih keren_
6
+
7
+ ---
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/belajar.svg)](http://badge.fury.io/rb/belajar)
10
+ [![Travis Build](https://travis-ci.com/wong-bejo/belajar.svg?branch=main)](https://travis-ci.com/wong-bejo/belajar)
11
+
12
+ With Belajar you can master your way of learning the Ruby programming
13
+ language with courses that are created by the community.
14
+
15
+ Belajar is a command line tool and a text based interface and provides
16
+ you with a number of learning tasks and explanations about the Ruby
17
+ programming language. You will learn Ruby step by step by solving small
18
+ language-explaining programming tasks.
19
+
20
+ ## Installation
21
+
22
+ First of all make sure Ruby is installed on your computer.
23
+ Belajar works with [MRI Ruby](https://www.ruby-lang.org/en/documentation/installation/) v2.5 or higher.
24
+
25
+ Then open a terminal and install Belajar by running:
26
+
27
+ $ gem install belajar
28
+
29
+ ## Get started
30
+
31
+ To get started open a terminal and run following line:
32
+
33
+ $ belajar welcome
34
+
35
+ Belajar will lead you through the setup and some important commands.
36
+
37
+ ## Command line interface
38
+
39
+ Belajar’s command line interface provides several commands which you
40
+ can use in your terminal to setup the system, download new courses,
41
+ and navigate through your solutions.
42
+
43
+ Please visit the [Belajar Wiki](https://github.com/wong-bejo/belajar/wiki/How-to-use-Belajar%27s-command-line-interface-%28CLI%29) to learn more about available commands.
44
+
45
+ ![Belajar CLI screenshot](https://res.cloudinary.com/paulgoetze/image/upload/v1520762037/belajar/belajar-cli-screenshot_xgpav6.png)
46
+
47
+ ## Belajar screen
48
+
49
+ Belajar’s text based interface—the Belajar screen—shows your installed courses and allows you to navigate through their chapters and units. In the task view you can read the unit’s task and validate your solution code.
50
+
51
+ Please visit the [Diagaku Wiki](https://github.com/wong-bejo/belajar/wiki/How-to-learn-Ruby-in-the-Belajar-screen) to learn how to use the Belajar screen.
52
+
53
+ ![Belajar screen screenshot](https://res.cloudinary.com/paulgoetze/image/upload/v1520762097/belajar/belajar-task-view_zbvsia.png)
54
+
55
+ ## Contributing
56
+
57
+ We encourage you to contribute to Belajar development and course creation.
58
+
59
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant Code of Conduct](https://github.com/wong-bejo/belajar/blob/master/CODE_OF_CONDUCT.md).
60
+
61
+ ### Development
62
+
63
+ Any ideas, feature proposals, filing and feedback on issues are very welcome.
64
+ We use the [git branching model](http://nvie.com/posts/a-successful-git-branching-model/) described by [nvie](https://github.com/nvie).
65
+
66
+ Here’s how to contribute:
67
+
68
+ 1. Fork it ( https://github.com/wong-bejo/belajar/fork )
69
+ 2. Create your feature branch (`git checkout -b feature/my-new-feature develop`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin feature/my-new-feature`)
72
+ 5. Create a new Pull Request
73
+
74
+ Please try to add RSpec tests with your new features. This will ensure that your code does not break existing functionality and that your feature is working as expected.
75
+
76
+ Ah, don’t forget step 6: Celebrate that you made Belajar a better tool after your code was merged in! :octocat: :tada:
2
77
 
3
78
  ### License
4
79
 
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
- task default: :spec
5
+ task default: :spec
@@ -3,36 +3,33 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'belajar/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "belajar"
6
+ spec.name = 'belajar'
7
7
  spec.version = Belajar::VERSION
8
- spec.required_ruby_version = '~> 2.0'
9
- spec.authors = ["Ahmad Ainul Rizki"]
10
- spec.email = ["hey@bejoistic.com"]
11
- spec.summary = %q{Learning Ruby on the command line.}
12
- spec.description = %q{Belajar is the Japanese word for university. With Belajar you can interactively learn the Ruby programming language using the command line.}
13
- spec.homepage = "https://github.com/wong-bejo/belajar"
14
- spec.license = "MIT"
15
-
8
+ spec.authors = ['Ahmad Ainul Rizki']
9
+ spec.email = ['hey@bejoistic.com']
10
+ spec.summary = 'Learning Ruby on the command line.'
11
+ spec.description = 'Belajar is the Japanese word for university. With Belajar you can interactively learn the Ruby programming language using the command line.'
12
+ spec.homepage = 'https://github.com/wong-bejo/belajar'
13
+ spec.license = 'MIT'
16
14
  spec.files = `git ls-files -z`.split("\x0")
17
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
17
+ spec.require_paths = ['lib']
20
18
 
21
- if RUBY_VERSION >= '2.1'
22
- spec.add_runtime_dependency "curses", ">= 1.0", "< 2.0"
23
- end
19
+ spec.required_ruby_version = '>= 2.5'
24
20
 
25
- spec.add_runtime_dependency "activesupport", ">= 4.0", "< 5.0"
26
- spec.add_runtime_dependency "rspec", ">= 3.0", "< 4.0"
27
- spec.add_runtime_dependency "thor", "~> 0.19.1"
28
- spec.add_runtime_dependency "os", "~> 0.9.6"
29
- spec.add_runtime_dependency "colorize", "~> 0.7.5"
30
- spec.add_runtime_dependency "rubyzip", ">= 1.0", "< 2.0"
31
- spec.add_runtime_dependency "wisper", ">= 2.0.0.rc1", "< 3.0"
32
- spec.add_runtime_dependency "quick_store", "~> 0.1.0"
21
+ spec.add_runtime_dependency 'curses', '~> 1.3'
22
+ spec.add_runtime_dependency 'rspec', '~> 3.0'
23
+ spec.add_runtime_dependency 'thor', '~> 1.0'
24
+ spec.add_runtime_dependency 'os', '~> 1.0'
25
+ spec.add_runtime_dependency 'colorize', '~> 0.8'
26
+ spec.add_runtime_dependency 'rubyzip', '~> 2.0'
27
+ spec.add_runtime_dependency 'wisper', '~> 2.0'
28
+ spec.add_runtime_dependency 'quick_store', '~> 1.0'
29
+ spec.add_runtime_dependency 'code_breaker', '~> 1.0'
33
30
 
34
- spec.add_development_dependency "bundler", "~> 1.7"
35
- spec.add_development_dependency "rake", "~> 10.0"
36
- spec.add_development_dependency "webmock", "~> 1.20.4"
37
- spec.add_development_dependency "guard-rspec", "~> 4.5.0"
38
- end
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'webmock', '~> 3.0'
34
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
35
+ end
Binary file
@@ -6,7 +6,11 @@ begin
6
6
  require 'belajar'
7
7
  rescue LoadError => e
8
8
  warn "could not load \"belajar\"\n#{e}"
9
- exit -1
9
+ exit(-1)
10
10
  end
11
11
 
12
- Belajar::Terminal::CLI.start
12
+ begin
13
+ Belajar::Terminal::CLI.start
14
+ rescue Interrupt
15
+ puts "\n\n\t👋 Sampai jumpa lagi!"
16
+ end
@@ -6,7 +6,6 @@ Dir[File.join("#{File.dirname(__FILE__)}/**/*.rb")].sort.each do |file|
6
6
  end
7
7
 
8
8
  module Belajar
9
-
10
9
  class << self
11
10
  def config
12
11
  Configuration.instance
@@ -1,10 +1,9 @@
1
1
  module Belajar
2
2
  class Chapter
3
-
4
3
  attr_reader :title, :path
5
4
 
6
5
  def initialize(path)
7
- @path = path
6
+ @path = path
8
7
  @title = File.basename(path).gsub(/\_+/, ' ')
9
8
  end
10
9
 
@@ -13,11 +12,11 @@ module Belajar
13
12
  end
14
13
 
15
14
  def started?
16
- units.reduce(false) { |started, unit| started ||= unit.mastered? }
15
+ units.any?(&:mastered?)
17
16
  end
18
17
 
19
18
  def mastered?
20
- units.reduce(true) { |mastered, unit| mastered &&= unit.mastered? }
19
+ units.all?(&:mastered?)
21
20
  end
22
21
  end
23
22
  end
@@ -0,0 +1,32 @@
1
+ require 'curses'
2
+
3
+ module Belajar
4
+ module Coloring
5
+ COLOR_TEXT = Curses::COLOR_YELLOW unless defined? COLOR_TEXT
6
+ COLOR_TEXT_EMPHASIZE = Curses::COLOR_CYAN unless defined? COLOR_TEXT_EMPHASIZE
7
+ COLOR_HEADING = Curses::COLOR_WHITE unless defined? COLOR_HEADING
8
+ COLOR_RED = Curses::COLOR_BLUE unless defined? COLOR_RED
9
+ COLOR_GREEN = Curses::COLOR_MAGENTA unless defined? COLOR_GREEN
10
+ COLOR_YELLOW = Curses::COLOR_RED unless defined? COLOR_YELLOW
11
+
12
+ BACKGROUND = Curses::COLOR_WHITE unless defined? BACKGROUND
13
+ FONT = Curses::COLOR_BLACK unless defined? FONT
14
+ FONT_HEADING = Curses::COLOR_MAGENTA unless defined? FONT_HEADING
15
+ FONT_EMPHASIZE = Curses::COLOR_BLUE unless defined? FONT_EMPHASIZE
16
+ RED = Curses::COLOR_RED unless defined? RED
17
+ GREEN = Curses::COLOR_GREEN unless defined? GREEN
18
+ YELLOW = Curses::COLOR_YELLOW unless defined? YELLOW
19
+
20
+ protected
21
+
22
+ def init_colors
23
+ Curses.start_color
24
+ Curses.init_pair(COLOR_TEXT, FONT, BACKGROUND)
25
+ Curses.init_pair(COLOR_TEXT_EMPHASIZE, FONT_EMPHASIZE, BACKGROUND)
26
+ Curses.init_pair(COLOR_HEADING, FONT_HEADING, BACKGROUND)
27
+ Curses.init_pair(COLOR_RED, RED, BACKGROUND)
28
+ Curses.init_pair(COLOR_GREEN, GREEN, BACKGROUND)
29
+ Curses.init_pair(COLOR_YELLOW, YELLOW, BACKGROUND)
30
+ end
31
+ end
32
+ end
@@ -1,15 +1,15 @@
1
- module Belajar
2
- require 'singleton'
3
- require 'fileutils'
1
+ require 'singleton'
2
+ require 'fileutils'
4
3
 
4
+ module Belajar
5
5
  class Configuration
6
6
  include Singleton
7
7
 
8
- LOCAL_DIR = '.belajar'
9
- COURSES_DIR = 'courses'
10
- SOLUTIONS_DIR = 'solutions'
11
- STORAGE_FILE = 'belajar.db.yml'
12
- BELAJAR_INITIAL_COURSE = 'wong-bejo/Get_started_with_Ruby'
8
+ LOCAL_DIR = '.belajar'.freeze
9
+ COURSES_DIR = 'courses'.freeze
10
+ SOLUTIONS_DIR = 'solutions'.freeze
11
+ STORAGE_FILE = 'belajar.db.yml'.freeze
12
+ BELAJAR_INITIAL_COURSE = 'wong-bejo/Belajar_Ruby'.freeze
13
13
 
14
14
  attr_accessor :courses_path
15
15
  attr_reader :storage_file
@@ -26,52 +26,50 @@ module Belajar
26
26
  end
27
27
 
28
28
  def solutions_path
29
- @solutions_path || raise(Belajar::ConfigurationError, 'Solutions path is not set.')
29
+ @solutions_path ||
30
+ raise(Belajar::ConfigurationError, 'Solutions path is not set.')
30
31
  end
31
32
 
32
33
  def solutions_path=(path)
33
34
  full_path = File.expand_path(path, Dir.pwd)
34
35
 
35
36
  unless Dir.exist?(full_path)
36
- error = [
37
+ raise(
37
38
  Belajar::ConfigurationError,
38
- "Solutions path \"#{path}\" isn't an existing directory."
39
- ]
40
-
41
- raise(*error)
39
+ "Solutions path \"#{path}\" isnt an existing directory."
40
+ )
42
41
  end
43
42
 
44
43
  @solutions_path = full_path
45
44
  end
46
45
 
47
46
  def save
48
- settings = self.instance_variables
47
+ settings = instance_variables
49
48
  settings.delete(:@storage_file)
50
49
 
51
50
  settings.each do |variable|
52
- key = variable.to_s.delete('@')
53
- value = self.instance_variable_get(variable.to_sym)
51
+ key = variable.to_s.delete('@')
52
+ value = instance_variable_get(variable.to_sym)
54
53
  QuickStore.store.set(key, value)
55
54
  end
56
55
  end
57
56
 
58
- def import!
59
- @courses_path = QuickStore.store.courses_path || @courses_path
60
- @solutions_path = QuickStore.store.solutions_path || @solutions_path
57
+ def import
58
+ store = QuickStore.store
59
+ @courses_path = store.courses_path || @courses_path
60
+ @solutions_path = store.solutions_path || @solutions_path
61
61
  self
62
62
  end
63
63
 
64
64
  def summary
65
- settings = self.instance_variables
65
+ settings = instance_variables
66
66
  settings.delete(:@storage_file)
67
67
 
68
- lines = settings.map do |variable|
69
- key = variable.to_s.delete('@').gsub('_', ' ')
70
- value = self.instance_variable_get(variable.to_sym)
71
- "* #{key}: #{value}"
68
+ settings.reduce('') do |lines, variable|
69
+ key = variable.to_s.delete('@').tr('_', ' ')
70
+ value = instance_variable_get(variable.to_sym)
71
+ lines + "* #{key}: #{value}\n"
72
72
  end
73
-
74
- lines.join("\n")
75
73
  end
76
74
 
77
75
  def initial_course
@@ -85,5 +83,4 @@ module Belajar
85
83
  File.expand_path(path, __FILE__)
86
84
  end
87
85
  end
88
-
89
86
  end
@@ -1,13 +1,25 @@
1
1
  module Belajar
2
-
3
2
  class Congratulator
4
-
5
3
  def self.message
6
- lines = Terminal.text(:congratulations).lines.map(&:strip).compact
7
- count = lines.count.zero? ? 0 : (lines.count - 1)
8
- random_value = rand(0..count)
4
+ new.message
5
+ end
6
+
7
+ def message
9
8
  lines[random_value]
10
9
  end
11
10
 
11
+ private
12
+
13
+ def lines
14
+ @lines ||= Terminal.text(:congratulations).lines.map(&:strip).compact
15
+ end
16
+
17
+ def random_value
18
+ rand(0..lines_count)
19
+ end
20
+
21
+ def lines_count
22
+ [lines.count - 1, 0].max
23
+ end
12
24
  end
13
25
  end