Class: Ataru::ArgumentChecker
- Inherits:
-
Object
- Object
- Ataru::ArgumentChecker
- Defined in:
- lib/ataru/argument_checker.rb
Instance Method Summary collapse
- #each ⇒ Object
- #exit_if_empty(file_names) ⇒ Object
-
#initialize(file_names) ⇒ ArgumentChecker
constructor
A new instance of ArgumentChecker.
- #verify(file_name) ⇒ Object
Constructor Details
#initialize(file_names) ⇒ ArgumentChecker
Returns a new instance of ArgumentChecker.
4 5 6 7 |
# File 'lib/ataru/argument_checker.rb', line 4 def initialize(file_names) exit_if_empty(file_names) @file_names = file_names end |
Instance Method Details
#each ⇒ Object
33 34 35 36 37 |
# File 'lib/ataru/argument_checker.rb', line 33 def each @file_names.each do |file_name| yield verify(file_name) end end |
#exit_if_empty(file_names) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/ataru/argument_checker.rb', line 9 def exit_if_empty(file_names) if file_names.empty? puts "ataru: command line usage error" puts "ataru: please give the file name" puts "usage: ataru.rb <filename>" exit 64 end end |
#verify(file_name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ataru/argument_checker.rb', line 18 def verify(file_name) if file_name !~ /.+\.md/ puts "ataru: data format error" puts "ataru: #{file_name} is not a markdown file" puts "ataru: markdown file required" exit 65 elsif File.file?(file_name) == false puts "ataru: cannot open input" puts "ataru: #{file_name} file not found" exit 66 else file_name end end |