Class: Iev::Cli::Command

Inherits:
Thor
  • Object
show all
Includes:
CommandHelper
Defined in:
lib/iev/cli/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ui

debug, error, info, progress, set_ui_tag, warn

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/iev/cli/command.rb', line 165

def self.exit_on_failure?
  true
end

Instance Method Details

#db2yaml(dbfile) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/iev/cli/command.rb', line 115

def db2yaml(dbfile)
  warn "[DEPRECATED] 'db2yaml' is deprecated. Use 'export' instead."
  handle_generic_options(options)

  Iev::Exporter.new(
    dbfile,
    output_dir: options[:output],
    only_concepts: options[:only_concepts],
    only_languages: options[:only_languages],
  ).export

  summary
end

#export(file) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/iev/cli/command.rb', line 44

def export(file)
  handle_generic_options(options)

  exporter = Iev::Exporter.new(
    file,
    output_dir: options[:output],
    only_concepts: options[:only_concepts],
    only_languages: options[:only_languages],
    fetch_relaton_links: options[:relaton],
    on_progress: method(:export_progress),
  )
  exporter.export
  print_export_summary(exporter.stats)
rescue ArgumentError => e
  error e.message
  exit 1
rescue Sequel::Error => e
  error "Database error: #{e.message}"
  exit 1
end

#fetch(code) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/iev/cli/command.rb', line 148

def fetch(code)
  raw = if options[:scrape]
          Scraper.new.fetch_concept(code)
        else
          DataSource.fetch_concept(code)
        end

  concept = build_concept_from_raw(code, raw)
  print_concept_grouped_yaml(concept)
rescue Iev::DataSource::NotFoundError
  error "IEV concept not found: #{code}"
  exit 1
rescue Ferrum::Error => e
  error "Scraping failed: #{e.message}"
  exit 1
end

#versionObject



12
13
14
# File 'lib/iev/cli/command.rb', line 12

def version
  puts "iev #{Iev::VERSION}"
end

#xlsx2db(file) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/iev/cli/command.rb', line 137

def xlsx2db(file)
  handle_generic_options(options)
  db = Sequel.sqlite
  DbWriter.new(db).import_spreadsheet(file)
  save_db_to_file(db, options[:output])
  summary
end

#xlsx2yaml(file) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/iev/cli/command.rb', line 83

def xlsx2yaml(file)
  warn "[DEPRECATED] 'xlsx2yaml' is deprecated. Use 'export' instead."
  handle_generic_options(options)

  Iev::Exporter.new(
    file,
    output_dir: options[:output],
    only_concepts: options[:only_concepts],
    only_languages: options[:only_languages],
  ).export

  summary
end