Module: CodewarsCli::FileParserHelpers
- Included in:
- Finalize, SubmitKata
- Defined in:
- lib/codewars_cli/file_parser_helpers.rb
Instance Method Summary collapse
- #_fetch_info(content, string) ⇒ Object
- #_kata_path(kata_name, language) ⇒ Object
- #_parse_description_file(kata_name, language) ⇒ Object
Instance Method Details
#_fetch_info(content, string) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/codewars_cli/file_parser_helpers.rb', line 14 def _fetch_info(content, string) regex = %r(#{string}: (.*)) if match = content.match(regex) match[1] else error("The #{string} is missing from your description.md") exit(1) end end |
#_kata_path(kata_name, language) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/codewars_cli/file_parser_helpers.rb', line 24 def _kata_path(kata_name, language) path = File.join(ENV['HOME'], Configuration.folder, kata_name, language) unless File.exist?(path) presenter.display_katas_info(kata_name, language) exit(1) end path end |
#_parse_description_file(kata_name, language) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/codewars_cli/file_parser_helpers.rb', line 5 def _parse_description_file(kata_name, language) Dir.chdir(_kata_path(kata_name, language)) do description_content = File.read(FileCreator::DESCRIPTION_FILE_NAME) project_id = _fetch_info(description_content, 'Project ID') solution_id = _fetch_info(description_content, 'Solution ID') OpenStruct.new(project_id: project_id, solution_id: solution_id) end end |