class Alfred3::Workflow
Public Class Methods
new()
click to toggle source
# File lib/alfred-3_workflow.rb, line 7 def initialize @results = [] end
Public Instance Methods
filter_results(query, property = 'title')
click to toggle source
# File lib/alfred-3_workflow.rb, line 31 def filter_results(query, property = 'title') query = query.to_s.strip.downcase return self if query.length === 0 @results.select! { |result| result.instance_variable_get("@#{property}").downcase.include? query } self end
output()
click to toggle source
# File lib/alfred-3_workflow.rb, line 44 def output { items: @results.map { |result| result.to_hash } }.to_json end
result()
click to toggle source
# File lib/alfred-3_workflow.rb, line 12 def result result = Result.new @results << result result end
sort_results(direction = 'asc', property = 'title')
click to toggle source
# File lib/alfred-3_workflow.rb, line 19 def sort_results(direction = 'asc', property = 'title') @results.sort! { |r1, r2| r1_prop = r1.instance_variable_get("@#{property}") r2_prop = r2.instance_variable_get("@#{property}") multiplier = direction === 'asc' ? 1 : -1 (r1_prop <=> r2_prop) * multiplier } self end