Skip to content

Commit 8df10ff

Browse files
committed
Updated SpreadSheets objects.
Mapping JSON responses to Eiffel object. (WIP)
1 parent 68dd53c commit 8df10ff

13 files changed

+650
-55
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 152 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ feature {NONE} -- JSON To Eiffel
8080

8181
eg_spreadsheet_properties (a_json: JSON_VALUE): EG_SPREADSHEET_PROPERTIES
8282
--
83+
local
84+
l_cell_format: EG_CELL_FORMAT
8385
do
8486
create Result
8587
if attached {JSON_OBJECT} json_value (a_json, "properties") as l_properties then
@@ -92,21 +94,167 @@ feature {NONE} -- JSON To Eiffel
9294
if attached string_value_from_json (l_properties, "autoRecalc") as l_auto_recalc then
9395
if l_auto_recalc.is_case_insensitive_equal ("ON_CHANGE") then
9496
Result.auto_recalc.set_on_change
95-
end
96-
if l_auto_recalc.is_case_insensitive_equal ("MINUTE") then
97+
elseif l_auto_recalc.is_case_insensitive_equal ("MINUTE") then
9798
Result.auto_recalc.set_minute
98-
end
99-
if l_auto_recalc.is_case_insensitive_equal ("HOUR") then
99+
elseif l_auto_recalc.is_case_insensitive_equal ("HOUR") then
100100
Result.auto_recalc.set_hour
101101
end
102102
end
103103
if attached string_value_from_json (l_properties, "timeZone") as l_time_zone then
104104
Result.set_time_zone (l_time_zone)
105105
end
106+
if attached {JSON_OBJECT} json_value (l_properties, "defaultFormat") as l_default_format then
107+
end
108+
end
109+
end
110+
111+
112+
default_format (a_json: JSON_OBJECT): EG_CELL_FORMAT
113+
do
114+
create Result
115+
116+
if attached {JSON_OBJECT} json_value (a_json, "backgroundColor") as l_background_color then
117+
Result.set_background_color (eg_color (l_background_color))
118+
end
119+
if attached {JSON_OBJECT} json_value (a_json, "padding") as l_padding then
120+
Result.set_padding (padding (l_padding))
121+
end
122+
if attached string_value_from_json (a_json, "verticalAlignment") as l_alignment then
123+
if l_alignment.is_case_insensitive_equal ("BOTTOM") then
124+
Result.vertical_alignment.set_bottom
125+
elseif l_alignment.is_case_insensitive_equal ("MIDDLE") then
126+
Result.vertical_alignment.set_middle
127+
elseif l_alignment.is_case_insensitive_equal ("TOP") then
128+
Result.vertical_alignment.set_top
129+
end
130+
end
131+
if attached string_value_from_json (a_json, "wrapStrategy") as l_wrap_strategy then
132+
if l_wrap_strategy.is_case_insensitive_equal ("OVERFLOW_CELL") then
133+
Result.wrap_strategy.set_overflow_cell
134+
end
135+
if l_wrap_strategy.is_case_insensitive_equal ("LEGACY_WRAP") then
136+
Result.wrap_strategy.set_legacy_wrap
137+
elseif l_wrap_strategy.is_case_insensitive_equal ("CLIP") then
138+
Result.wrap_strategy.set_clip
139+
elseif l_wrap_strategy.is_case_insensitive_equal ("WRAP") then
140+
Result.wrap_strategy.set_wrap
141+
end
142+
end
143+
if attached {JSON_OBJECT} json_value (a_json, "textFormat") as l_text_format then
144+
Result.set_text_format (text_format (l_text_format))
145+
end
146+
if attached {JSON_OBJECT} json_value (a_json, "backgroundColorStyle") as l_background_color_style then
147+
Result.set_background_color_style (eg_color_style (l_background_color_style))
148+
end
149+
end
150+
151+
eg_color (a_json: JSON_OBJECT): EG_COLOR
152+
do
153+
create Result
154+
if attached integer_value_from_json (a_json, "red") as l_val then
155+
Result.set_red (l_val)
156+
elseif attached real_value_from_json (a_json, "red") as l_val then
157+
Result.set_red (l_val)
158+
end
159+
if attached integer_value_from_json (a_json, "green") as l_val then
160+
Result.set_green (l_val)
161+
elseif attached real_value_from_json (a_json, "green") as l_val then
162+
Result.set_green (l_val)
163+
end
164+
if attached integer_value_from_json (a_json, "blue") as l_val then
165+
Result.set_blue (l_val)
166+
elseif attached real_value_from_json (a_json, "blue") as l_val then
167+
Result.set_blue (l_val)
168+
end
169+
if attached integer_value_from_json (a_json, "alpha") as l_val then
170+
Result.set_alpha (l_val)
171+
elseif attached real_value_from_json (a_json, "alpha") as l_val then
172+
Result.set_alpha (l_val)
173+
end
174+
end
175+
176+
padding (a_json: JSON_OBJECT): EG_PADDING
177+
do
178+
create Result
179+
if attached integer_value_from_json (a_json, "top") as l_val then
180+
Result.set_top (l_val)
181+
end
182+
if attached integer_value_from_json (a_json, "right") as l_val then
183+
Result.set_right (l_val)
184+
end
185+
if attached integer_value_from_json (a_json, "bottom") as l_val then
186+
Result.set_bottom (l_val)
187+
end
188+
if attached integer_value_from_json (a_json, "left") as l_val then
189+
Result.set_left (l_val)
190+
end
191+
end
192+
193+
text_format (a_json: JSON_OBJECT): EG_TEXT_FORMAT
194+
do
195+
create Result
196+
if attached {JSON_OBJECT} json_value (a_json, "foregroundColor") as l_foreground_color then
197+
Result.set_foreground_color (eg_color (l_foreground_color))
198+
end
199+
if attached {JSON_OBJECT} json_value (a_json, "foregroundColorStyle") as l_foreground_color_style then
200+
Result.set_foreground_color_style (eg_color_style (l_foreground_color_style))
201+
end
202+
if attached string_value_from_json (a_json, "fontFamily") as l_font_family then
203+
Result.set_font_family (l_font_family)
204+
end
205+
if attached integer_value_from_json (a_json, "fontSize") as l_font_size then
206+
Result.set_font_size (l_font_size)
207+
end
208+
if attached boolean_value_from_json (a_json, "bold") as l_bold then
209+
Result.set_bold (l_bold)
210+
end
211+
if attached boolean_value_from_json (a_json, "italic") as l_italic then
212+
Result.set_italic (l_italic)
213+
end
214+
if attached boolean_value_from_json (a_json, "strikethrough") as l_strikethrough then
215+
Result.set_strikethrough (l_strikethrough)
216+
end
217+
if attached boolean_value_from_json (a_json, "underline") as l_underline then
218+
Result.set_strikethrough (l_underline)
219+
end
220+
end
221+
222+
eg_color_style (a_json: JSON_OBJECT): EG_COLOR_STYLE
223+
local
224+
l_tc: EG_THEME_COLOR
225+
do
226+
create Result
227+
if attached {JSON_OBJECT} json_value (a_json, "rgbColor") as l_rgbcolor then
228+
Result.set_rgb (eg_color (l_rgbcolor))
229+
elseif
230+
attached string_value_from_json (a_json, "themeColor") as l_theme_color
231+
then
232+
create l_tc
233+
if l_theme_color.is_case_insensitive_equal ("TEXT") then
234+
l_tc.set_text
235+
elseif l_theme_color.is_case_insensitive_equal ("BACKGROUND") then
236+
l_tc.set_background
237+
elseif l_theme_color.is_case_insensitive_equal ("ACCENT1") then
238+
l_tc.set_accent1
239+
elseif l_theme_color.is_case_insensitive_equal ("ACCENT2") then
240+
l_tc.set_accent2
241+
elseif l_theme_color.is_case_insensitive_equal ("ACCENT3") then
242+
l_tc.set_accent3
243+
elseif l_theme_color.is_case_insensitive_equal ("ACCENT4") then
244+
l_tc.set_accent4
245+
elseif l_theme_color.is_case_insensitive_equal ("ACCENT5") then
246+
l_tc.set_accent5
247+
elseif l_theme_color.is_case_insensitive_equal ("ACCENT6") then
248+
l_tc.set_accent6
249+
elseif l_theme_color.is_case_insensitive_equal ("LINK") then
250+
l_tc.set_link
251+
end
252+
Result.set_theme_color (l_tc)
106253
end
107254
end
108255

109256

257+
110258
feature {NONE} -- Implementation
111259

112260
eg_sheets_api: EG_SHEETS_API

sheets/src/objects/eg_cell_format.e

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,72 @@ feature -- Access
8989
text_format: EG_TEXT_FORMAT
9090
-- The format of the text in the cell (unless overridden by a format run).
9191

92-
hyperlinkDisplayType: detachable EG_HYPERLINK_DISPLAY_TYPE
92+
hyperlink_display_type: detachable EG_HYPERLINK_DISPLAY_TYPE
9393
-- How a hyperlink, if it exists, should be displayed in the cell.
9494

9595
text_rotation: detachable EG_TEXT_ROTATION
9696
-- The rotation applied to text in a cell
97+
98+
feature -- Change Element
99+
100+
set_number_format (a_format: EG_NUMBER_FORMAT)
101+
do
102+
number_format := a_format
103+
end
104+
105+
set_background_color (a_bg_color: EG_COLOR)
106+
do
107+
background_color := a_bg_color
108+
end
109+
110+
set_background_color_style (a_bg_color_style: EG_COLOR_STYLE)
111+
do
112+
background_color_style := a_bg_color_style
113+
end
114+
115+
set_borders (a_borders: EG_BORDERS)
116+
do
117+
borders := a_borders
118+
end
119+
120+
set_padding (a_padding: EG_PADDING)
121+
do
122+
padding := a_padding
123+
end
124+
125+
set_horizontal_alignment (ha: EG_HORIZONTAL_ALIGN)
126+
do
127+
horizontal_alignment := ha
128+
end
129+
130+
set_vertical_alignment (a_val: EG_VERTICAL_ALIGN)
131+
do
132+
vertical_alignment := a_val
133+
end
134+
135+
set_wrap_strategy (a_val: EG_WRAP_STRATEGY)
136+
do
137+
wrap_strategy := a_val
138+
end
139+
140+
set_text_direction (a_val: EG_TEXT_DIRECTION)
141+
do
142+
text_direction := a_val
143+
end
144+
145+
set_text_format (a_val: EG_TEXT_FORMAT)
146+
do
147+
text_format := a_val
148+
end
149+
150+
set_hyperlink_display_type (a_val: EG_HYPERLINK_DISPLAY_TYPE)
151+
do
152+
hyperlink_display_type := a_val
153+
end
154+
155+
set_text_rotation (a_val: EG_TEXT_ROTATION)
156+
do
157+
text_rotation := a_val
158+
end
159+
97160
end

sheets/src/objects/eg_color.e

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ feature {NONE} -- Access
2020

2121
default_create
2222
do
23-
red := 1.0
24-
green := 1.0
25-
blue := 1.0
26-
alpha := 1.0
23+
red := 0.0
24+
green := 0.0
25+
blue := 0.0
26+
alpha := 0.0
2727
end
2828

2929
feature -- Access
@@ -44,6 +44,38 @@ feature -- Access
4444
-- This uses a wrapper message rather than a simple float scalar so that it is possible to distinguish between a default value and the value being unset.
4545
-- If omitted, this color object is to be rendered as a solid color (as if the alpha value had been explicitly given with a value of 1.0).
4646

47+
48+
feature -- Change Element
49+
50+
set_red (a_val: REAL)
51+
do
52+
red := a_val
53+
ensure
54+
red_set: red = a_val
55+
end
56+
57+
set_green (a_val: REAL)
58+
do
59+
green := a_val
60+
ensure
61+
green_set: green = a_val
62+
end
63+
64+
set_blue (a_val: REAL)
65+
do
66+
blue := a_val
67+
ensure
68+
blue_set: blue = a_val
69+
end
70+
71+
set_alpha (a_val: REAL)
72+
do
73+
alpha := a_val
74+
ensure
75+
alpha_set: alpha = a_val
76+
end
77+
78+
4779
invariant
4880
red_invariant: red >= 0.0 and then red <= 1.0
4981
green_invariant: green >= 0.0 and then green <= 1.0

sheets/src/objects/eg_color_style.e

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,6 @@ note
2020
class
2121
EG_COLOR_STYLE
2222

23-
inherit
24-
ANY
25-
redefine
26-
default_create
27-
end
28-
29-
create
30-
default_create
31-
32-
33-
feature {NONE} -- Initialization
34-
35-
default_create
36-
do
37-
create rgb_color
38-
end
39-
4023
feature -- Access
4124

4225
rgb_color: detachable EG_COLOR
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
note
2-
description: "Summary description for {EG_ITERATIVE_CALCULATION_SETTINGS}."
3-
author: ""
2+
description: "Settings to control how circular dependencies are resolved with iterative calculation."
43
date: "$Date$"
54
revision: "$Revision$"
5+
EIS: "name=Iteratice calculation settings", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#iterativecalculationsettings", "protocol=uri"
66

77
class
88
EG_ITERATIVE_CALCULATION_SETTINGS
99

10+
feature -- Access
11+
12+
max_iterations: INTEGER
13+
-- When iterative calculation is enabled, the maximum number of calculation rounds to perform.
14+
15+
convergence_threshold: INTEGER
16+
-- When iterative calculation is enabled and successive results differ by less than this threshold value, the calculation rounds stop.
17+
18+
19+
feature -- Change Element
20+
21+
set_max_iterations (a_val: INTEGER)
22+
-- Set `max_iterations` with `a_val`.
23+
do
24+
max_iterations := a_val
25+
ensure
26+
max_iterations_set: max_iterations = a_val
27+
end
28+
29+
set_convergence_threshold (a_val: INTEGER)
30+
-- Set `convergence_threshold` with `a_val`.
31+
do
32+
convergence_threshold := a_val
33+
ensure
34+
convergence_threshold_set: convergence_threshold = a_val
35+
end
1036
end
37+

0 commit comments

Comments
 (0)