alfred-3_workflow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/alfred-3_workflow.rb +53 -0
- data/lib/result.rb +155 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9afcb630b25283ebe539e76f39fdd9496b0b743f
|
4
|
+
data.tar.gz: 92cb7176538639c7c676b9fa8de33982b738b3b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c69e511de255f5d7289c7878b0ded51f537ddb1ce4688f3aa7b3e41d75a190bed2d1b06c6fdfa8d8a2b04b9fa4e72210a9ded40e9d4cd31a873044c101a8206a
|
7
|
+
data.tar.gz: 27e4fc47ca4efdb26f9684cff83959a6898dc7fe3a84d0c266771b3a09cd3fd512c29d4ebbaa4daaf46981359d880276b93269b80a847e89d3569ed71e0bc90b
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'result'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Alfred3
|
5
|
+
class Workflow
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@results = []
|
9
|
+
end
|
10
|
+
|
11
|
+
public
|
12
|
+
def result
|
13
|
+
result = Result.new
|
14
|
+
@results << result
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
public
|
19
|
+
def sort_results(direction = 'asc', property = 'title')
|
20
|
+
@results.sort! { |r1, r2|
|
21
|
+
r1_prop = r1.instance_variable_get("@#{property}")
|
22
|
+
r2_prop = r2.instance_variable_get("@#{property}")
|
23
|
+
multiplier = direction === 'asc' ? 1 : -1
|
24
|
+
(r1_prop <=> r2_prop) * multiplier
|
25
|
+
}
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
def filter_results(query, property = 'title')
|
32
|
+
query = query.to_s.strip.downcase
|
33
|
+
|
34
|
+
return self if query.length === 0
|
35
|
+
|
36
|
+
@results.select! { |result|
|
37
|
+
result.instance_variable_get("@#{property}").downcase.include? query
|
38
|
+
}
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
public
|
44
|
+
def output
|
45
|
+
{
|
46
|
+
items: @results.map { |result|
|
47
|
+
result.to_hash
|
48
|
+
}
|
49
|
+
}.to_json
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/lib/result.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
class Result
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@arg = nil
|
5
|
+
@autocomplete = nil
|
6
|
+
@icon = nil
|
7
|
+
@mods = {}
|
8
|
+
@quicklookurl = nil
|
9
|
+
@subtitle = nil
|
10
|
+
@text = {}
|
11
|
+
@title = nil
|
12
|
+
@type = nil
|
13
|
+
@uid = nil
|
14
|
+
@valid = true
|
15
|
+
|
16
|
+
@simple_values = [
|
17
|
+
'arg',
|
18
|
+
'autocomplete',
|
19
|
+
'quicklookurl',
|
20
|
+
'subtitle',
|
21
|
+
'title',
|
22
|
+
'uid',
|
23
|
+
]
|
24
|
+
|
25
|
+
@valid_values = {
|
26
|
+
type: ['default', 'file', 'file:skipcheck'],
|
27
|
+
icon: ['fileicon', 'filetype'],
|
28
|
+
text: ['copy', 'largetype'],
|
29
|
+
mod: ['shift', 'fn', 'ctrl', 'alt', 'cmd']
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
public
|
34
|
+
def valid(valid)
|
35
|
+
@valid = !!valid
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
public
|
40
|
+
def type(type, verify_existence = true)
|
41
|
+
return self unless @valid_values[:type].include?(type.to_s)
|
42
|
+
|
43
|
+
if type === 'file' && !verify_existence
|
44
|
+
@type = 'file:skipcheck'
|
45
|
+
else
|
46
|
+
@type = type
|
47
|
+
end
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
public
|
53
|
+
def icon(path, type = nil)
|
54
|
+
@icon = {
|
55
|
+
path: path
|
56
|
+
}
|
57
|
+
|
58
|
+
@icon[:type] = type if @valid_values[:icon].include?(type.to_s)
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
public
|
64
|
+
def fileicon_icon(path)
|
65
|
+
icon(path, 'fileicon')
|
66
|
+
end
|
67
|
+
|
68
|
+
public
|
69
|
+
def filetype_icon(path)
|
70
|
+
icon(path, 'filetype')
|
71
|
+
end
|
72
|
+
|
73
|
+
public
|
74
|
+
def text(type, text)
|
75
|
+
return self unless @valid_values[:text].include?(type.to_s)
|
76
|
+
|
77
|
+
@text[type.to_sym] = text
|
78
|
+
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
public
|
83
|
+
def mod(mod, subtitle, arg, valid = true)
|
84
|
+
return self unless @valid_values[:mod].include?(mod.to_s)
|
85
|
+
|
86
|
+
@mods[mod.to_sym] = {
|
87
|
+
subtitle: subtitle,
|
88
|
+
arg: arg,
|
89
|
+
valid: valid
|
90
|
+
}
|
91
|
+
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
public
|
96
|
+
def to_hash
|
97
|
+
keys = [
|
98
|
+
'arg',
|
99
|
+
'autocomplete',
|
100
|
+
'icon',
|
101
|
+
'mods',
|
102
|
+
'quicklookurl',
|
103
|
+
'subtitle',
|
104
|
+
'text',
|
105
|
+
'title',
|
106
|
+
'type',
|
107
|
+
'uid',
|
108
|
+
'valid',
|
109
|
+
]
|
110
|
+
|
111
|
+
result = {}
|
112
|
+
|
113
|
+
keys.each { |key|
|
114
|
+
result[key.to_sym] = self.instance_variable_get("@#{key}")
|
115
|
+
}
|
116
|
+
|
117
|
+
result.select { |hash_key, hash_value|
|
118
|
+
(hash_value.class.to_s === 'Hash' && !hash_value.empty?) || (hash_value.class.to_s != 'Hash' && !hash_value.nil?)
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def method_missing(method, *arguments)
|
123
|
+
if @simple_values.include?(method.to_s)
|
124
|
+
self.instance_variable_set("@#{method}", arguments.first)
|
125
|
+
return self
|
126
|
+
end
|
127
|
+
|
128
|
+
if @valid_values[:mod].include?(method.to_s)
|
129
|
+
return mod(method, *arguments)
|
130
|
+
end
|
131
|
+
|
132
|
+
if @valid_values[:text].include?(method.to_s)
|
133
|
+
return text(method, *arguments)
|
134
|
+
end
|
135
|
+
|
136
|
+
super
|
137
|
+
end
|
138
|
+
|
139
|
+
def respond_to?(method, include_private = false)
|
140
|
+
if @simple_values.include?(method.to_s)
|
141
|
+
return true
|
142
|
+
end
|
143
|
+
|
144
|
+
if @valid_values[:mod].include?(method.to_s)
|
145
|
+
return true
|
146
|
+
end
|
147
|
+
|
148
|
+
if @valid_values[:text].include?(method.to_s)
|
149
|
+
return true
|
150
|
+
end
|
151
|
+
|
152
|
+
super
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alfred-3_workflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe Tannenbaum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Easily generate Alfred 3 workflow results in a fluent manner.
|
14
|
+
email: joe@joe.codes
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/alfred-3_workflow.rb
|
20
|
+
- lib/result.rb
|
21
|
+
homepage: https://github.com/joetannenbaum/alfred-workflow-ruby
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.14.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Helper library for creating Alfred 3 Workflows
|
45
|
+
test_files: []
|