Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/jott/config.rb
Instance Attribute Summary collapse
-
#editor ⇒ Object
readonly
Returns the value of attribute editor.
Instance Method Summary collapse
- #get_editor ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #set_editor(editor) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
4 5 6 7 8 9 10 |
# File 'lib/jott/config.rb', line 4 def initialize @file_path = File.join("#{File.dirname(__FILE__)}", "jott.config") unless File.exist?(@file_path) File.new(@file_path, "w") end @editor = get_editor end |
Instance Attribute Details
#editor ⇒ Object (readonly)
Returns the value of attribute editor.
2 3 4 |
# File 'lib/jott/config.rb', line 2 def editor @editor end |
Instance Method Details
#get_editor ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jott/config.rb', line 12 def get_editor File.open(@file_path, "r") do |file| file.each_line do |line| if line.include?("editor") return line.split(":")[1].strip else return "vi" end end end end |
#set_editor(editor) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/jott/config.rb', line 24 def set_editor(editor) File.open(@file_path, "w") do |file| file.puts "editor: #{editor}" end @editor = editor end |