Class: Ucode::Cli::CodeChartCmd

Inherits:
Thor
  • Object
show all
Defined in:
lib/ucode/cli.rb

Overview

─────────────── code-chart ─────────────── Extract per-codepoint SVG glyphs from a Unicode Code Charts PDF. One folder per block under --to, with <U+XXXX>.svg + .json pairs.

Instance Method Summary collapse

Instance Method Details

#extract(version = nil) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ucode/cli.rb', line 185

def extract(version = nil)
  with_codechart_errors do
    version_str = VersionResolver.resolve(version)
    block = resolve_block!(options[:block], version_str)
    block_first_cp = block.range_first

    # Download (idempotent — re-runs skip when the PDF is cached).
    Commands::FetchCommand.new.fetch_charts(version_str, block_first_cps: [block_first_cp])

    pdf = Ucode::Glyphs::PdfFetcher.new(version_str)
      .fetch(block_first_cp: block_first_cp)
    raise Ucode::CodeChartNotFoundError.new(
      "Code Charts PDF unavailable for block #{block.id.inspect}",
      context: { block_id: block.id, version: version_str },
    ) unless pdf

    writer = Ucode::CodeChart::Writer.new(
      output_root: Pathname.new(options[:to]),
      pdf_path: pdf,
      ucd_version: version_str,
    )
    summary = writer.write(block)
    puts JSON.pretty_generate(summary.to_h.compact)
  end
end

#fetch(version = nil) ⇒ Object



168
169
170
171
172
173
174
175
176
177
# File 'lib/ucode/cli.rb', line 168

def fetch(version = nil)
  with_codechart_errors do
    block_first_cp = resolve_block_first_cp!(options[:block], version)
    result = Commands::FetchCommand.new.fetch_charts(
      VersionResolver.resolve(version),
      block_first_cps: [block_first_cp],
    )
    puts JSON.pretty_generate(result)
  end
end

#listObject



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/ucode/cli.rb', line 212

def list
  version = VersionResolver.resolve(nil)
  pdfs_dir = Ucode::Cache.pdfs_dir(version)
  files = pdfs_dir.exist? ? pdfs_dir.children.sort : []
  if files.empty?
    puts "(no cached Code Charts PDFs)"
    return
  end
  files.each do |f|
    puts f.basename.to_s
  end
end