Class: Appydave::Tools::Jump::Commands::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/appydave/tools/jump/commands/query.rb

Overview

Query command provides scriptable location lookup

Designed for pipeline use — default output is bare paths, one per line. Use –meta for structured JSON output.

Examples:

Find by term

cmd = Commands::Query.new(config, find: ['flivideo'])
result = cmd.run
result[:results]  # => Array of matching location hashes

Filter by type

cmd = Commands::Query.new(config, type: 'product')
result = cmd.run

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #options, #path_validator

Instance Method Summary collapse

Constructor Details

#initialize(config, **options) ⇒ Query

Returns a new instance of Query.



23
24
25
26
27
28
# File 'lib/appydave/tools/jump/commands/query.rb', line 23

def initialize(config, **options)
  super
  @find_terms  = Array(options[:find]).map { |t| t.to_s.downcase.strip }.reject(&:empty?)
  @type_filter = normalize_option(options[:type])
  @brand_filter = normalize_option(options[:brand])
end

Instance Attribute Details

#brand_filterObject (readonly)

Returns the value of attribute brand_filter.



21
22
23
# File 'lib/appydave/tools/jump/commands/query.rb', line 21

def brand_filter
  @brand_filter
end

#find_termsObject (readonly)

Returns the value of attribute find_terms.



21
22
23
# File 'lib/appydave/tools/jump/commands/query.rb', line 21

def find_terms
  @find_terms
end

#type_filterObject (readonly)

Returns the value of attribute type_filter.



21
22
23
# File 'lib/appydave/tools/jump/commands/query.rb', line 21

def type_filter
  @type_filter
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/appydave/tools/jump/commands/query.rb', line 30

def run
  matches = config.locations.select { |loc| matches?(loc) }

  if matches.empty?
    return error_result(
      'No locations found matching the given criteria',
      code: 'NOT_FOUND'
    )
  end

  results = matches.map.with_index(1) do |location, index|
    location_to_result(location, index)
  end

  success_result(
    count: results.size,
    results: results
  )
end