Conversation
…nslation of RSS to JSON works correctly.
bin/converter.rb
Outdated
| require 'open-uri' | ||
| require 'nokogiri' | ||
| require 'json' | ||
| require '../lib/readers/link_reader' |
There was a problem hiding this comment.
А через require_all не пробовал добавлять всю папку сразу?
bin/converter.rb
Outdated
| require 'open-uri' | ||
| require 'nokogiri' | ||
| require 'json' | ||
| require '../lib/readers/link_reader' |
There was a problem hiding this comment.
Вообще, подключать файла из папки lib надо в main. В этом файле надо подключать библиотеку optparse и сам main файл. Bin/converter мы можем убрать и должны мочь запустить только main, например, из консоли, и он должен заработать.
lib/converters/atom_converter.rb
Outdated
| result_xml += "</entry>\n" | ||
| end | ||
| result_xml += "</feed>" | ||
| File.open("../test/fixtures/file1", "w") do |file| |
There was a problem hiding this comment.
Добавь расширение к файлу, например, data.atom.
lib/converters/converter.rb
Outdated
| @@ -0,0 +1,14 @@ | |||
| class Converter | |||
There was a problem hiding this comment.
Предпочтительнее переименовать в BaseConverter
lib/readers/file_reader.rb
Outdated
| file_contents.each do |line| | ||
| data += line | ||
| end | ||
| return data |
There was a problem hiding this comment.
return можно не писать
lib/readers/reader.rb
Outdated
| def self.read(input) | ||
| if input.include?('http://') | ||
| LinkReader.read(input) | ||
| else FileReader.read(input) |
There was a problem hiding this comment.
Проблема с отступами и переносами.
There was a problem hiding this comment.
Исправил при помощи rubocop -a
test/lib/readers/file_reade_testr.rb
Outdated
|
|
||
|
|
||
| class Reader | ||
| attr_accessor :input |
There was a problem hiding this comment.
Можно не объявлять. А в методе read обратиться, как @input
test/lib/readers/file_reade_testr.rb
Outdated
| file_contents.each do |line| | ||
| data += line | ||
| end | ||
| return data |
test/lib/readers/link_reader_test.rb
Outdated
| require 'open-uri' | ||
|
|
||
|
|
||
| class Reader |
There was a problem hiding this comment.
А зачем объявлять данный класс? Надо использовать тот, который в программе main используется, мы его тестировать должны.
| @@ -0,0 +1,19 @@ | |||
| class Main | |||
There was a problem hiding this comment.
PARSERS = ['JsonParser', 'AtomParser', 'RssParser']
main.rb
Outdated
|
|
||
| def run | ||
| data = Reader.read(@input) | ||
| parsed_data = Parser.parse(data) |
There was a problem hiding this comment.
Main::PARSERS.each do |parser_name|
return parser_name if Module.const_get(parser_name).can_parse?(data)
end
| } | ||
| end | ||
| result | ||
| end |
There was a problem hiding this comment.
def self.can_parse?(data)
data.include?('{')
end
lib/converters/rss_converter.rb
Outdated
| result_xml += "</item>\n" | ||
| end | ||
| puts result_xml += '</rss>' | ||
| File.open('../test/fixtures/file1.rss', 'w') do |file| |
There was a problem hiding this comment.
Я бы всё-таки разбил функционал метод на 2 - непосредственно конвертацию в xml и записб в файл.
main.rb
Outdated
| parsed_data = Module.const_get(input_format).parse(data) | ||
| if @sort == 'asc' || @sort == 'desc' | ||
| sorted_data = @sort == 'asc' ? AscSorter.sort(parsed_data) : DescSorter.sort(parsed_data) | ||
| convert_data = BaseConverter.new(@output) |
There was a problem hiding this comment.
Дублирование кода! И ниже ещё 2 строчки. Надо убрать.
No description provided.