Class: Alfred::Feedback::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/alfred/feedback/item.rb

Direct Known Subclasses

FileItem

Constant Summary collapse

Default_Order =
256

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argObject

Returns the value of attribute arg.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def arg
  @arg
end

#autocompleteObject

Returns the value of attribute autocomplete.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def autocomplete
  @autocomplete
end

#iconObject

Returns the value of attribute icon.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def icon
  @icon
end

#orderObject

Returns the value of attribute order.



7
8
9
# File 'lib/alfred/feedback/item.rb', line 7

def order
  @order
end

#subtitleObject

Returns the value of attribute subtitle.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def title
  @title
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def type
  @type
end

#uidObject

Returns the value of attribute uid.



6
7
8
# File 'lib/alfred/feedback/item.rb', line 6

def uid
  @uid
end

#validObject

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

Returns:

  • (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

Returns:

  • (Boolean)


85
86
87
# File 'lib/alfred/feedback/item.rb', line 85

def always_match?(query)
  true
end

#match?(query) ⇒ Boolean

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

Returns:

  • (Boolean)


78
79
80
# File 'lib/alfred/feedback/item.rb', line 78

def match?(query)
  send(@matcher, query)
end

#title_match?(query) ⇒ Boolean

Returns:

  • (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_xmlObject



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