Class: PromptLine
- Inherits:
-
Object
- Object
- PromptLine
- Defined in:
- lib/prompt_line.rb
Instance Method Summary collapse
-
#initialize(attribute, prompt_exclusions = []) ⇒ PromptLine
constructor
A new instance of PromptLine.
- #message ⇒ Object
- #prompt ⇒ Object
- #save(input) ⇒ Object
Constructor Details
#initialize(attribute, prompt_exclusions = []) ⇒ PromptLine
Returns a new instance of PromptLine.
6 7 8 9 |
# File 'lib/prompt_line.rb', line 6 def initialize(attribute, prompt_exclusions = []) @attribute = attribute @prompt_exclusions = prompt_exclusions end |
Instance Method Details
#message ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/prompt_line.rb', line 28 def previous = saved_data = "\n" += "previous #{@attribute}: #{previous}\n" unless previous.empty? puts "#{@attribute}: " end |
#prompt ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/prompt_line.rb', line 11 def prompt return nil if @prompt_exclusions.include?(@attribute) input = nil loop do input = Readline.readline().chomp break unless (input.empty? && saved_data.empty?) end unless input.empty? save(input) return input end puts "using: #{saved_data}" return saved_data end |
#save(input) ⇒ Object
36 37 38 |
# File 'lib/prompt_line.rb', line 36 def save(input) File.open(path(@attribute), "w") {|f| f.write(input) } end |