Skip to content

Commit 9f969b3

Browse files
committed
Add common function
1 parent e78647b commit 9f969b3

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

run.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def read_schema(schema)
1010
data
1111
end
1212

13+
# function
14+
def ii(i)
15+
i.positive? ? i : ''
16+
end
17+
1318
repo = Rugged::Repository.new('.')
1419
branches = repo.branches.each_name(:local).sort
1520

@@ -82,8 +87,8 @@ def draw_chart(which_chart, data, chart_string, chart_values,
8287
# build all the website pages
8388
def page_build(page_count)
8489
(0..page_count).map do |i|
85-
instance_variable_set("@page#{i > 0 ? i : ''}",
86-
instance_variable_get("@page#{i > 0 ? i : ''}") + $page)
90+
instance_variable_set("@page#{ii i}",
91+
instance_variable_get("@page#{ii i}") + $page)
8792
end
8893
end
8994

@@ -92,7 +97,7 @@ def add_links(page_count)
9297
page = ''
9398
(0..page_count).map do |i|
9499
page += %(
95-
<li><a href="index#{i > 0 ? i : ''}.html">Page #{i + 1}</a></li>)
100+
<li><a href="index#{ii i}.html">Page #{i + 1}</a></li>)
96101
end
97102
page
98103
end
@@ -156,7 +161,7 @@ def clean_chart(chart)
156161
# try 50 chart sections per page
157162
page_count = structure.size / 50
158163
(0..page_count).map do |i|
159-
instance_variable_set("@page#{i > 0 ? i : ''}", $page)
164+
instance_variable_set("@page#{ii i}", $page)
160165
end
161166
# restart common page region
162167
$page = add_links(page_count)
@@ -177,17 +182,17 @@ def clean_chart(chart)
177182
k = i
178183
i /= 50
179184
# put each chart type in its own row
180-
instance_variable_set("@page#{i > 0 ? i : ''}",
181-
instance_variable_get("@page#{i > 0 ? i : ''}") + "
185+
instance_variable_set("@page#{ii i}",
186+
instance_variable_get("@page#{ii i}") + "
182187
<h2>#{k + 1}. Branch count of schema by #{token[0][0].delete '<'}</h2>
183188
<div class=\"row\">")
184189
token.map.with_index(1) do |chart, j|
185190
data0 = clean_chart(chart[0]) + j.to_s
186-
instance_variable_set("@page#{i > 0 ? i : ''}",
187-
instance_variable_get("@page#{i > 0 ? i : ''}") + "\n <div class=\"col-sm-6 col-md-4 col-lg-3\" id=\"chart_div_#{data0}\"></div>")
191+
instance_variable_set("@page#{ii i}",
192+
instance_variable_get("@page#{ii i}") + "\n <div class=\"col-sm-6 col-md-4 col-lg-3\" id=\"chart_div_#{data0}\"></div>")
188193
end
189-
instance_variable_set("@page#{i > 0 ? i : ''}",
190-
instance_variable_get("@page#{i > 0 ? i : ''}") + '
194+
instance_variable_set("@page#{ii i}",
195+
instance_variable_get("@page#{ii i}") + '
191196
<div class="navarrows">
192197
<a href="#head1">&#8593;</a>
193198
<a href="#theend">&#8595;</a>
@@ -283,8 +288,8 @@ def clean_chart(chart)
283288
colors = data1.map { |d| schema_colors[d[0]] }
284289
v = 'Values'
285290
i = ind / 50
286-
instance_variable_set("@page#{i > 0 ? i : ''}",
287-
instance_variable_get("@page#{i > 0 ? i : ''}") + " google.charts.setOnLoadCallback(drawChart#{data0});\n" + draw_chart(data0, data1, chart[0], v, chart_title(chart[0], ind * 3 + j, branches[j - 1]), data0, width, height, colors))
291+
instance_variable_set("@page#{ii i}",
292+
instance_variable_get("@page#{ii i}") + " google.charts.setOnLoadCallback(drawChart#{data0});\n" + draw_chart(data0, data1, chart[0], v, chart_title(chart[0], ind * 3 + j, branches[j - 1]), data0, width, height, colors))
288293
end
289294
end
290295

@@ -312,7 +317,7 @@ def clean_chart(chart)
312317
page_build(page_count)
313318
# write all the HTML pages to files
314319
(0..page_count).map do |i|
315-
file = File.open("index#{i > 0 ? i : ''}.html", 'w')
316-
file.write(instance_variable_get("@page#{i > 0 ? i : ''}"))
320+
file = File.open("index#{ii i}.html", 'w')
321+
file.write(instance_variable_get("@page#{ii i}"))
317322
file.close
318323
end

0 commit comments

Comments
 (0)