-
Notifications
You must be signed in to change notification settings - Fork 21
/
parse.rb
40 lines (33 loc) · 923 Bytes
/
parse.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
# @example
# curl https://raw.githubusercontent.com/Ghosh/uiGradients/master/gradients.json | ruby parse.rb
require "json"
require "erb"
require 'active_support/core_ext/string/inflections'
def parse(body)
@colors = JSON.parse(body).map do |color|
{
"name" => color["name"],
"classified_name" => color["name"].split(" ").join(""),
"camelized_name" => color["name"].split(" ").join("").camelize(:lower), # dirty
"start_color_hex" => color["colour1"],
"end_color_hex" => color["colour2"]
}
end
end
def render_h
ERB.new(File.read("UIColor+uiGradients.h.erb")).result()
end
def render_m
ERB.new(File.read("UIColor+uiGradients.m.erb")).result()
end
def write
File.open("UIColor+uiGradients.h", "w") do |f|
f.write render_h
end
File.open("UIColor+uiGradients.m", "w") do |f|
f.write render_m
end
end
json_string = ARGF.read
parse(json_string)
write()