Class: Patinfo2csv::CLI
- Inherits:
-
Object
- Object
- Patinfo2csv::CLI
- Defined in:
- lib/patinfo2csv/cli.rb
Class Method Summary collapse
- .output_rows(rows, output_file) ⇒ Object
- .parse_txt(code_txt) ⇒ Object
- .report(rows, nomatches, lang) ⇒ Object
-
.run(patinfo_yaml, code_txt, output_file, lang) ⇒ Object
- Param
- patinfo_yaml patinfo.yaml Param
- code_txt eancode.txt Param
- output_file patinfo.csv Param
-
lang (de|fr).
Class Method Details
.output_rows(rows, output_file) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/patinfo2csv/cli.rb', line 35 def output_rows(rows, output_file) return unless rows open(output_file, "w:utf-8") do |out| rows.each do |row| out.print row, "\n" end end end |
.parse_txt(code_txt) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/patinfo2csv/cli.rb', line 26 def parse_txt(code_txt) codes = [] File.open(code_txt, "r:utf-8") do |input| while line = input.gets codes << line.gsub(/[^\d]/, '').chomp end end codes end |
.report(rows, nomatches, lang) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/patinfo2csv/cli.rb', line 43 def report(rows, nomatches, lang) count = 0 if rows count = rows.length - 1 end puts "patinfo[#{lang}] converted: #{count.to_s} rows" unless nomatches.empty? puts "-----" puts "There is no chapters of Patinfo of the following " \ "#{nomatches.length.to_s} codes" puts "[#{nomatches.join(',')}]" puts end end |
.run(patinfo_yaml, code_txt, output_file, lang) ⇒ Object
- Param
-
patinfo_yaml patinfo.yaml
- Param
-
code_txt eancode.txt
- Param
-
output_file patinfo.csv
- Param
-
lang (de|fr)
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/patinfo2csv/cli.rb', line 14 def run(patinfo_yaml, code_txt, output_file, lang) start = Time.now loader = Patinfo2csv::Loader.new() converter = Patinfo2csv::Converter.new() converter.patinfos = loader.load_yaml(patinfo_yaml) converter.lang = lang converter.codes = self.parse_txt(code_txt) rows = converter.to_csv self.output_rows(rows, output_file) report(rows, converter.codes, lang) puts "#{Time.now - start} sec." end |