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



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/ucode/cli.rb', line 157

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)
    unless pdf
      raise Ucode::CodeChartNotFoundError.new(
        "Code Charts PDF unavailable for block #{block.id.inspect}",
        context: { block_id: block.id, version: version_str },
      )
    end

    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



140
141
142
143
144
145
146
147
148
149
# File 'lib/ucode/cli.rb', line 140

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



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/ucode/cli.rb', line 186

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
  end
end