-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-more-acronyms.rb
52 lines (45 loc) · 1.19 KB
/
no-more-acronyms.rb
1
2
3
4
5
6
7
8
9
10
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
require 'bundler/inline'
require 'yaml'
gemfile do
source 'https://rubygems.org'
gem 'nokogiri'
end
class NoMoreAcronyms
def initialize(path)
dict = YAML.load_file(path)
builder = build_plist(dict)
output_path = "results/#{File.basename(path, ".yml")}.plist"
create_result_file(builder, output_path)
end
private
def build_plist(acronyms)
Nokogiri::XML::Builder.new do |xml|
xml.doc.create_internal_subset(
'plist',
"-//Apple//DTD PLIST 1.0//EN",
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"
)
xml.plist('version' => '1.0') {
xml.array {
eval(acronyms.inspect)[0].each do |acronym, value|
xml.dict {
xml.key 'phrase'
xml.string value
xml.key 'shortcut'
xml.string acronym
}
end
}
}
end
end
def create_result_file(builder, file_path)
File.open(file_path, "w+") { |file| file.write(builder.to_xml) }
puts "#{file_path} CREATED"
end
end
ARGV.each do |path|
NoMoreAcronyms.new(path)
end
puts
puts 'Drag created files to Settings > Keyboard > Text configuration window' if ARGV.length > 0