Skip to content

Commit d64682c

Browse files
committed
Updated Eiffel to JSON mapping (WIP)
1 parent 67cde83 commit d64682c

11 files changed

+479
-14
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ feature {NONE} -- JSON To Eiffel
135135
Result.set_time_zone (l_time_zone)
136136
end
137137
if attached {JSON_OBJECT} json_value (a_json, "defaultFormat") as l_default_format then
138+
Result.set_default_format (cell_format (l_default_format))
139+
end
140+
if attached {JSON_OBJECT} json_value (a_json, "iterativeCalculationSettings") as iterativeCalculationSettings then
141+
-- Result.set_iterative_calculation_settings (a_iterative_calculation_settings: [like iterative_calculation_settings] detachable EG_ITERATIVE_CALCULATION_SETTINGS)
142+
end
143+
if attached {JSON_OBJECT} json_value (a_json, "spreadsheetTheme") as spreadsheetTheme then
144+
-- Result.set_spreadsheet_theme (a_theme: [like spreadsheet_theme] detachable EG_SPREADSHEET_THEME)
138145
end
139146
end
140147

@@ -143,15 +150,38 @@ feature {NONE} -- JSON To Eiffel
143150
local
144151
l_vl: EG_VERTICAL_ALIGN
145152
l_ws: EG_WRAP_STRATEGY
153+
l_hl: EG_HORIZONTAL_ALIGN
154+
l_td: EG_TEXT_DIRECTION
155+
l_hyper: EG_HYPERLINK_DISPLAY_TYPE
146156
do
147157
create Result
158+
if attached {JSON_OBJECT} json_value (a_json, "numberFormat") as l_number_format then
159+
Result.set_number_format (Void)
160+
end
148161

149162
if attached {JSON_OBJECT} json_value (a_json, "backgroundColor") as l_background_color then
150163
Result.set_background_color (eg_color (l_background_color))
151164
end
165+
if attached {JSON_OBJECT} json_value (a_json, "backgroundColorStyle") as l_background_color_style then
166+
Result.set_background_color_style (eg_color_style (l_background_color_style))
167+
end
168+
if attached {JSON_OBJECT} json_value (a_json, "borders") as l_borders then
169+
Result.set_borders (Void)
170+
end
152171
if attached {JSON_OBJECT} json_value (a_json, "padding") as l_padding then
153172
Result.set_padding (padding (l_padding))
154173
end
174+
if attached string_value_from_json (a_json, "horizontalAlignment") as l_alignment then
175+
create l_hl
176+
if l_alignment.is_case_insensitive_equal ("LEFT") then
177+
l_hl.set_left
178+
elseif l_alignment.is_case_insensitive_equal ("CENTER") then
179+
l_hl.set_center
180+
elseif l_alignment.is_case_insensitive_equal ("RIGHT") then
181+
l_hl.set_right
182+
end
183+
Result.set_horizontal_alignment (l_hl)
184+
end
155185
if attached string_value_from_json (a_json, "verticalAlignment") as l_alignment then
156186
create l_vl
157187
if l_alignment.is_case_insensitive_equal ("BOTTOM") then
@@ -177,11 +207,43 @@ feature {NONE} -- JSON To Eiffel
177207
end
178208
Result.set_wrap_strategy (l_ws)
179209
end
210+
if attached string_value_from_json (a_json, "textDirection") as l_text_direction then
211+
create l_td
212+
if l_text_direction.is_case_insensitive_equal ("LEFT_TO_RIGHT") then
213+
l_td.set_left_to_right
214+
end
215+
if l_text_direction.is_case_insensitive_equal ("RIGHT_TO_LEFT") then
216+
l_td.set_right_to_left
217+
end
218+
Result.set_text_direction (l_td)
219+
end
180220
if attached {JSON_OBJECT} json_value (a_json, "textFormat") as l_text_format then
181221
Result.set_text_format (text_format (l_text_format))
182222
end
183-
if attached {JSON_OBJECT} json_value (a_json, "backgroundColorStyle") as l_background_color_style then
184-
Result.set_background_color_style (eg_color_style (l_background_color_style))
223+
if attached string_value_from_json (a_json, "hyperlinkDisplayType") as hyperlink then
224+
create l_hyper
225+
if hyperlink.is_case_insensitive_equal ("LINKED") then
226+
l_hyper.set_linked
227+
end
228+
if hyperlink.is_case_insensitive_equal ("PLAIN_TEXT") then
229+
l_hyper.set_plain_text
230+
end
231+
Result.set_hyperlink_display_type (l_hyper)
232+
end
233+
if attached {JSON_OBJECT} json_value (a_json, "textRotation") as l_text_rotation then
234+
Result.set_text_rotation (text_rotation (l_text_rotation))
235+
end
236+
end
237+
238+
text_rotation (a_json: JSON_OBJECT): EG_TEXT_ROTATION
239+
-- Create an object `EG_TEXT_ROTATION` from a json representation.
240+
do
241+
create Result
242+
if attached integer_value_from_json (a_json, "angle") as l_val then
243+
Result.set_angle (l_val)
244+
end
245+
if attached boolean_value_from_json (a_json, "vertical") as l_val then
246+
Result.set_vertical (l_val)
185247
end
186248
end
187249

sheets/src/objects/eg_cell_format.e

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,27 @@ feature -- Eiffel to JSON
224224
if attached padding as l_padding then
225225
Result.put (l_padding.to_json, "padding")
226226
end
227+
if attached horizontal_alignment as l_ha then
228+
Result.put (l_ha.to_json, "horizontalAlignment")
229+
end
230+
if attached vertical_alignment as l_va then
231+
Result.put (l_va.to_json, "verticalAlignment")
232+
end
233+
if attached wrap_strategy as l_ws then
234+
Result.put (l_ws.to_json, "wrapStrategy")
235+
end
236+
if attached text_direction as l_td then
237+
Result.put (l_td.to_json, "textDirection")
238+
end
239+
if attached text_format as l_tf then
240+
Result.put (l_tf.to_json, "textFormat")
241+
end
242+
if attached hyperlink_display_type as l_hyper then
243+
Result.put (l_hyper.to_json, "hyperlinkDisplayType")
244+
end
245+
if attached text_rotation as l_rt then
246+
Result.put (l_rt.to_json, "textRotation")
247+
end
227248

228249
end
229250
end
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,114 @@
11
note
2-
description: "Summary description for {EG_HORIZONTAL_ALIGN}."
3-
author: ""
2+
description: "[
3+
The horizontal alignment of text in a cell.
4+
5+
Enums
6+
HORIZONTAL_ALIGN_UNSPECIFIED The horizontal alignment is not specified. Do not use this.
7+
LEFT The text is explicitly aligned to the left of the cell.
8+
CENTER The text is explicitly aligned to the center of the cell.
9+
RIGHT The text is explicitly aligned to the right of the cell.
10+
]"
411
date: "$Date$"
512
revision: "$Revision$"
13+
EIS: "name=HorizontalAlign ", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#horizontalalign", "protocol=uri"
614

715
class
816
EG_HORIZONTAL_ALIGN
917

18+
inherit
19+
20+
EG_ENUM
21+
redefine
22+
default_create
23+
end
24+
25+
create
26+
default_create
27+
28+
feature {NONE} -- Initialization
29+
30+
default_create
31+
do
32+
Precursor
33+
set_value (horizontal_align_unspecified)
34+
end
35+
36+
horizontal_align_unspecified: INTEGER = 1
37+
-- The horizontal alignment is not specified. Do not use this.
38+
39+
left: INTEGER = 2
40+
-- The text is explicitly aligned to the left of the cell.
41+
42+
center: INTEGER = 3
43+
-- The text is explicitly aligned to the center of the cell.
44+
45+
right: INTEGER = 4
46+
-- The text is explicitly aligned to the right of the cell.
47+
48+
feature -- Change Elements
49+
50+
set_left
51+
do
52+
set_value (left)
53+
ensure
54+
value_set_with_left: value = left
55+
end
56+
57+
set_center
58+
do
59+
set_value (center)
60+
ensure
61+
value_set_with_center: value = center
62+
end
63+
64+
set_right
65+
do
66+
set_value (right)
67+
ensure
68+
value_set_with_right: value = right
69+
end
70+
71+
feature -- Status Report
72+
73+
is_left: BOOLEAN
74+
do
75+
Result := value = left
76+
end
77+
78+
is_center: BOOLEAN
79+
do
80+
Result := value = center
81+
end
82+
83+
is_right: BOOLEAN
84+
do
85+
Result := value = right
86+
end
87+
88+
is_valid_value (a_value: INTEGER): BOOLEAN
89+
-- Can `a_value' be used in a `set_value' feature call?
90+
do
91+
Result := a_value = horizontal_align_unspecified or else
92+
a_value = left or else
93+
a_value = center or else
94+
a_value = right
95+
end
96+
97+
feature -- Eiffel to JSON
98+
99+
to_json: JSON_STRING
100+
do
101+
if is_left then
102+
Result := "LEFT"
103+
elseif is_center then
104+
Result := "CENTER"
105+
elseif is_right then
106+
Result := "RIGHT"
107+
else
108+
Result := "HORIZONTAL_ALIGN_UNSPECIFIED"
109+
end
110+
111+
end
112+
10113

11114
end
Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,94 @@
11
note
2-
description: "Summary description for {EG_HYPERLINK_DISPLAY_TYPE}."
3-
author: ""
2+
description: "[
3+
Whether to explicitly render a hyperlink. If not specified, the hyperlink is linked.
4+
5+
Enums
6+
HYPERLINK_DISPLAY_TYPE_UNSPECIFIED The default value: the hyperlink is rendered. Do not use this.
7+
LINKED A hyperlink should be explicitly rendered.
8+
PLAIN_TEXT A hyperlink should not be rendered.
9+
10+
]"
411
date: "$Date$"
512
revision: "$Revision$"
13+
EIS: "name=HyperlinkDisplayType", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#hyperlinkdisplaytype", "protocol=uri"
614

715
class
816
EG_HYPERLINK_DISPLAY_TYPE
917

18+
inherit
19+
20+
EG_ENUM
21+
redefine
22+
default_create
23+
end
24+
25+
create
26+
default_create
27+
28+
feature {NONE} -- Initialization
29+
30+
default_create
31+
do
32+
Precursor
33+
set_value (hyperlink_display_type_unspecified)
34+
end
35+
36+
hyperlink_display_type_unspecified: INTEGER = 1
37+
-- The default value: the hyperlink is rendered. Do not use this.
38+
39+
linked: INTEGER = 2
40+
-- A hyperlink should be explicitly rendered.
41+
42+
plain_text: INTEGER = 3
43+
-- A hyperlink should not be rendered.
44+
45+
feature -- Change Elements
46+
47+
set_linked
48+
do
49+
set_value (linked)
50+
ensure
51+
value_set_with_linked: value = linked
52+
end
53+
54+
set_plain_text
55+
do
56+
set_value (plain_text)
57+
ensure
58+
value_set_with_plain_text: value = plain_text
59+
end
60+
61+
feature -- Status Report
62+
63+
is_linked: BOOLEAN
64+
do
65+
Result := value = linked
66+
end
67+
68+
is_plain_text: BOOLEAN
69+
do
70+
Result := value = plain_text
71+
end
72+
73+
is_valid_value (a_value: INTEGER): BOOLEAN
74+
-- Can `a_value' be used in a `set_value' feature call?
75+
do
76+
Result := a_value = hyperlink_display_type_unspecified or else
77+
a_value = linked or else
78+
a_value = plain_text
79+
end
80+
81+
feature -- Eiffel to JSON
82+
83+
to_json: JSON_STRING
84+
do
85+
if is_linked then
86+
Result := "LINKED"
87+
elseif is_plain_text then
88+
Result := "PLAIN_TEXT"
89+
else
90+
Result := "HYPERLINK_DISPLAY_TYPE_UNSPECIFIED"
91+
end
92+
end
93+
1094
end

sheets/src/objects/eg_spreadsheet_properties.e

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ feature -- Eiffel to JSON
134134
if attached time_zone as l_time_zone then
135135
Result.put (create {JSON_STRING}.make_from_string (l_time_zone), "timeZone")
136136
end
137+
if attached default_format as l_format then
138+
Result.put (l_format.to_json ,"defaultFormat")
139+
end
137140
if attached iterative_calculation_settings as l_ics then
138141
Result.put (l_ics.to_json, "iterativeCalculationSettings")
139142
end

0 commit comments

Comments
 (0)