class Alfred::Feedback::Item
Constants
- Default_Order
Attributes
arg[RW]
autocomplete[RW]
icon[RW]
order[RW]
subtitle[RW]
title[RW]
type[RW]
uid[RW]
valid[RW]
Public Class Methods
new(title, opts = {})
click to toggle source
# File lib/alfred/feedback/item.rb, line 11 def initialize(title, opts = {}) @title = title @subtitle = opts[:subtitle] if opts[:subtitle] if opts[:icon] @icon = opts[:icon] else @icon ||= {:type => "default", :name => "icon.png"} end if opts[:uid] @uid = opts[:uid] end if opts[:arg] @arg = opts[:arg] else @arg ||= @title end if opts[:type] @type = opts[:type] else @type ||= 'default' end if opts[:valid] @valid = opts[:valid] else @valid ||= 'yes' end if opts[:autocomplete] @autocomplete = opts[:autocomplete] end if opts[:match?] @matcher = opts[:match?].to_sym else @matcher ||= :title_match? end if opts[:order] @order = opts[:order] else @order = Default_Order end end
Public Instance Methods
<=>(other)
click to toggle source
sort function
# File lib/alfred/feedback/item.rb, line 62 def <=>(other) @order <=> other.order end
all_title_match?(query)
click to toggle source
# File lib/alfred/feedback/item.rb, line 98 def all_title_match?(query) return true if query.empty? if query.is_a? String query = query.split("\s") end queries = [] query.each { |q| queries << smartcase_query(q) } queries.delete_if { |q| q.match(@title) or q.match(@subtitle) } if queries.empty? return true else return false end end
always_match?(query)
click to toggle source
Matchers
# File lib/alfred/feedback/item.rb, line 85 def always_match?(query) true end
match?(query)
click to toggle source
To customize a new matcher?, define it.
Module Alfred
class Feedback class Item def your_match?(query) # define new matcher here end end end
end
# File lib/alfred/feedback/item.rb, line 78 def match?(query) send(@matcher, query) end
title_match?(query)
click to toggle source
# File lib/alfred/feedback/item.rb, line 89 def title_match?(query) return true if query.empty? if smartcase_query(query).match(@title) return true else return false end end
to_xml()
click to toggle source
# File lib/alfred/feedback/item.rb, line 121 def to_xml xml_element = REXML::Element.new('item') if @uid xml_element.add_attributes({ 'uid' => @uid, 'valid' => @valid, 'autocomplete' => @autocomplete }) else xml_element.add_attributes({ 'valid' => @valid, 'autocomplete' => @autocomplete }) end xml_element.add_attributes('type' => 'file') if @type == "file" REXML::Element.new("title", xml_element).text = @title REXML::Element.new("arg", xml_element).text = @arg REXML::Element.new("subtitle", xml_element).text = @subtitle icon = REXML::Element.new("icon", xml_element) icon.text = @icon[:name] icon.add_attributes('type' => 'fileicon') if @icon[:type] == "fileicon" xml_element end
Protected Instance Methods
build_regexp(query, option)
click to toggle source
Regex helpers
# File lib/alfred/feedback/item.rb, line 154 def build_regexp(query, option) begin Regexp.compile(".*#{query.gsub(/\s+/,'.*')}.*", option) rescue RegexpError Regexp.compile(".*#{Regexp.escape(query)}.*", option) end end
default_query(query)
click to toggle source
# File lib/alfred/feedback/item.rb, line 181 def default_query(query) if query.is_a? Array query = query.join(" ") end build_regexp(query, nil) end
ignorecase_query(query)
click to toggle source
# File lib/alfred/feedback/item.rb, line 173 def ignorecase_query(query) if query.is_a? Array query = query.join(" ") end option = Regexp::IGNORECASE build_regexp(query, option) end
smartcase_query(query)
click to toggle source
# File lib/alfred/feedback/item.rb, line 162 def smartcase_query(query) if query.is_a? Array query = query.join(" ") end option = Regexp::IGNORECASE if /[[:upper:]]/.match(query) option = nil end build_regexp(query, option) end