Class: Edoxen::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/edoxen/cli.rb,
sig/edoxen.rbs

Defined Under Namespace

Modules: Batch

Constant Summary collapse

PROFILES =

Returns:

{
  decisions: Profile.new(
    "decisions", "edoxen.yaml",
    lambda do |content|
      data = YAML.safe_load(content, permitted_classes: [Date, Time])
      case Batch.decision_kind(data)
      when :contacts then ContactRegister.from_yaml(content)
      when :venues   then VenueRegister.from_yaml(content)
      else                DecisionCollection.from_yaml(content)
      end
    end
  ),
  meetings: Profile.new(
    "meetings", "meeting.yaml",
    lambda do |content|
      data = YAML.safe_load(content, permitted_classes: [Date, Time])
      case Batch.meetings_kind(data)
      when :collection then MeetingCollection.from_yaml(content)
      when :series     then MeetingSeries.from_yaml(content)
      else                  Meeting.from_yaml(content)
      end
    end
  )
}.freeze
Profile =

Returns:

  • (Struct[untyped])

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.

Parameters:

  • args (Object)


576
# File 'sig/edoxen.rbs', line 576

def initialize: (*untyped args) -> void

Instance Method Details



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/edoxen/cli.rb', line 201

def check_links(directory)
  unless File.directory?(directory)
    say "Error: #{directory} is not a directory", :red
    exit 1
  end

  say "🔗 Checking cross-document URN links in #{directory}...", :blue
  errors = Edoxen::LinkChecker.check(directory)
  return say("✅ No broken or duplicate links found", :green) if errors.empty?

  say "❌ Found #{errors.size} link error(s):", :red
  errors.each { |e| say "  #{e.message}", :red }
  exit 1
end

#iata(code) ⇒ void

This method returns an undefined value.

Parameters:

  • code (String)


239
240
241
242
243
244
245
246
247
248
249
# File 'lib/edoxen/cli.rb', line 239

def iata(code)
  entry = Edoxen::ReferenceData.find_iata(code)
  if entry.nil?
    say "No entry for #{code.upcase} in the IATA registry.", :red
    exit 1
  end

  say "IATA:       #{entry.code}", :blue
  say "  Name:      #{entry.name}"
  say "  Country:   #{entry.country_iso2}"
end

#normalize(pattern) ⇒ void

This method returns an undefined value.

Parameters:

  • pattern (String)


172
173
174
# File 'lib/edoxen/cli.rb', line 172

def normalize(pattern)
  run_normalize(PROFILES.fetch(:decisions), pattern)
end

#normalize_meetings(pattern) ⇒ void

This method returns an undefined value.

Parameters:

  • pattern (String)


191
192
193
# File 'lib/edoxen/cli.rb', line 191

def normalize_meetings(pattern)
  run_normalize(PROFILES.fetch(:meetings), pattern)
end

#unlocode(code) ⇒ void

This method returns an undefined value.

Parameters:

  • code (String)


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/edoxen/cli.rb', line 220

def unlocode(code)
  entry = Edoxen::ReferenceData.find_unlocode(code)
  if entry.nil?
    say "No entry for #{code.upcase} in the UN/LOCODE registry.", :red
    exit 1
  end

  say "UN/LOCODE:  #{entry.code}", :blue
  say "  Name:      #{entry.name}"
  say "  Country:   #{entry.country}"
  say "  Subdiv:    #{entry.subdivision}" if entry.subdivision
  coords = entry.coordinates
  say "  Coords:    #{coords}" if coords
  funcs = entry.function_codes.compact
  say "  Functions: #{funcs.join(", ")}" unless funcs.empty?
end

#validate(pattern) ⇒ void

This method returns an undefined value.

Parameters:

  • pattern (String)


162
163
164
# File 'lib/edoxen/cli.rb', line 162

def validate(pattern)
  run_validate(PROFILES.fetch(:decisions), pattern)
end

#validate_meetings(pattern) ⇒ void

This method returns an undefined value.

Parameters:

  • pattern (String)


181
182
183
# File 'lib/edoxen/cli.rb', line 181

def validate_meetings(pattern)
  run_validate(PROFILES.fetch(:meetings), pattern)
end