Class: Alfred::Feedback::Item
- Inherits:
-
Object
- Object
- Alfred::Feedback::Item
- Defined in:
- lib/alfred/feedback/item.rb
Direct Known Subclasses
Constant Summary collapse
- Default_Order =
256
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#autocomplete ⇒ Object
Returns the value of attribute autocomplete.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#order ⇒ Object
Returns the value of attribute order.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sort function.
- #all_title_match?(query) ⇒ Boolean
-
#always_match?(query) ⇒ Boolean
Matchers.
-
#initialize(title, opts = {}) ⇒ Item
constructor
A new instance of Item.
-
#match?(query) ⇒ Boolean
To customize a new matcher?, define it.
- #title_match?(query) ⇒ Boolean
- #to_xml ⇒ Object
Constructor Details
#initialize(title, opts = {}) ⇒ Item
Returns a new instance of Item.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def arg @arg end |
#autocomplete ⇒ Object
Returns the value of attribute autocomplete.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def autocomplete @autocomplete end |
#icon ⇒ Object
Returns the value of attribute icon.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def icon @icon end |
#order ⇒ Object
Returns the value of attribute order.
7 8 9 |
# File 'lib/alfred/feedback/item.rb', line 7 def order @order end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def subtitle @subtitle end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def type @type end |
#uid ⇒ Object
Returns the value of attribute uid.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def uid @uid end |
#valid ⇒ Object
Returns the value of attribute valid.
6 7 8 |
# File 'lib/alfred/feedback/item.rb', line 6 def valid @valid end |
Instance Method Details
#<=>(other) ⇒ Object
sort function
62 63 64 |
# File 'lib/alfred/feedback/item.rb', line 62 def <=>(other) @order <=> other.order end |
#all_title_match?(query) ⇒ Boolean
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# 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) ⇒ Boolean
Matchers
85 86 87 |
# File 'lib/alfred/feedback/item.rb', line 85 def always_match?(query) true end |
#match?(query) ⇒ Boolean
78 79 80 |
# File 'lib/alfred/feedback/item.rb', line 78 def match?(query) send(@matcher, query) end |
#title_match?(query) ⇒ Boolean
89 90 91 92 93 94 95 96 |
# 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 ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# 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 |