Skip to content

Commit 67cde83

Browse files
committed
Added to_json feature to EG_PADDING.
Updated EG_CELL_FORMAT, all features are detachable, updated to_json feature.
1 parent 06b8c11 commit 67cde83

File tree

3 files changed

+105
-47
lines changed

3 files changed

+105
-47
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ feature {NONE} -- JSON To Eiffel
140140

141141
cell_format (a_json: JSON_OBJECT): EG_CELL_FORMAT
142142
-- Create an object `EG_CELL_FORMAT` from a json representation `a_json`
143+
local
144+
l_vl: EG_VERTICAL_ALIGN
145+
l_ws: EG_WRAP_STRATEGY
143146
do
144147
create Result
145148

@@ -150,25 +153,29 @@ feature {NONE} -- JSON To Eiffel
150153
Result.set_padding (padding (l_padding))
151154
end
152155
if attached string_value_from_json (a_json, "verticalAlignment") as l_alignment then
156+
create l_vl
153157
if l_alignment.is_case_insensitive_equal ("BOTTOM") then
154-
Result.vertical_alignment.set_bottom
158+
l_vl.set_bottom
155159
elseif l_alignment.is_case_insensitive_equal ("MIDDLE") then
156-
Result.vertical_alignment.set_middle
160+
l_vl.set_middle
157161
elseif l_alignment.is_case_insensitive_equal ("TOP") then
158-
Result.vertical_alignment.set_top
162+
l_vl.set_top
159163
end
164+
Result.set_vertical_alignment (l_vl)
160165
end
161166
if attached string_value_from_json (a_json, "wrapStrategy") as l_wrap_strategy then
167+
create l_ws
162168
if l_wrap_strategy.is_case_insensitive_equal ("OVERFLOW_CELL") then
163-
Result.wrap_strategy.set_overflow_cell
169+
l_ws.set_overflow_cell
164170
end
165171
if l_wrap_strategy.is_case_insensitive_equal ("LEGACY_WRAP") then
166-
Result.wrap_strategy.set_legacy_wrap
172+
l_ws.set_legacy_wrap
167173
elseif l_wrap_strategy.is_case_insensitive_equal ("CLIP") then
168-
Result.wrap_strategy.set_clip
174+
l_ws.set_clip
169175
elseif l_wrap_strategy.is_case_insensitive_equal ("WRAP") then
170-
Result.wrap_strategy.set_wrap
176+
l_ws.set_wrap
171177
end
178+
Result.set_wrap_strategy (l_ws)
172179
end
173180
if attached {JSON_OBJECT} json_value (a_json, "textFormat") as l_text_format then
174181
Result.set_text_format (text_format (l_text_format))

sheets/src/objects/eg_cell_format.e

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,55 +38,37 @@ note
3838
class
3939
EG_CELL_FORMAT
4040

41-
inherit
42-
43-
ANY
44-
redefine
45-
default_create
46-
end
47-
48-
feature {NONE} -- Initialization
49-
50-
default_create
51-
do
52-
create background_color
53-
create background_color_style
54-
create padding
55-
create vertical_alignment
56-
create text_format
57-
create wrap_strategy
58-
end
5941

6042
feature -- Access
6143

6244
number_format: detachable EG_NUMBER_FORMAT
6345
-- A format describing how number values should be represented to the user.
6446

65-
background_color: EG_COLOR
47+
background_color: detachable EG_COLOR
6648
-- The background color of the cell.
6749

68-
background_color_style: EG_COLOR_STYLE
50+
background_color_style: detachable EG_COLOR_STYLE
6951
-- The background color of the cell. If backgroundColor is also set, this field takes precedence.
7052

7153
borders: detachable EG_BORDERS
7254
-- The borders of the cell.
7355

74-
padding: EG_PADDING
56+
padding: detachable EG_PADDING
7557
-- The padding of the cell.
7658

7759
horizontal_alignment: detachable EG_HORIZONTAL_ALIGN
7860
-- The horizontal alignment of the value in the cell.
7961

80-
vertical_alignment: EG_VERTICAL_ALIGN
62+
vertical_alignment: detachable EG_VERTICAL_ALIGN
8163
-- The vertical alignment of the value in the cell.
8264

83-
wrap_strategy: EG_WRAP_STRATEGY
65+
wrap_strategy: detachable EG_WRAP_STRATEGY
8466
-- The wrap strategy for the value in the cell.
8567

8668
text_direction: detachable EG_TEXT_DIRECTION
8769
-- The direction of the text in the cell.
8870

89-
text_format: EG_TEXT_FORMAT
71+
text_format: detachable EG_TEXT_FORMAT
9072
-- The format of the text in the cell (unless overridden by a format run).
9173

9274
hyperlink_display_type: detachable EG_HYPERLINK_DISPLAY_TYPE
@@ -97,64 +79,100 @@ feature -- Access
9779

9880
feature -- Change Element
9981

100-
set_number_format (a_format: EG_NUMBER_FORMAT)
82+
set_number_format (a_format: like number_format)
83+
-- Set `number_format` with `a_format`
10184
do
10285
number_format := a_format
86+
ensure
87+
number_format_set: number_format = a_format
10388
end
10489

105-
set_background_color (a_bg_color: EG_COLOR)
90+
set_background_color (a_bg_color: like background_color)
91+
-- Set `background_color` with `a_bg_color`
10692
do
10793
background_color := a_bg_color
94+
ensure
95+
background_color_set: background_color = a_bg_color
10896
end
10997

110-
set_background_color_style (a_bg_color_style: EG_COLOR_STYLE)
98+
set_background_color_style (a_bg_color_style: like background_color_style)
99+
-- Set `background_color_style` with `a_bg_colot_style`.
111100
do
112101
background_color_style := a_bg_color_style
102+
ensure
103+
background_color_style_set: background_color_style = a_bg_color_style
113104
end
114105

115-
set_borders (a_borders: EG_BORDERS)
106+
set_borders (a_borders: like borders)
107+
-- Set `borders` with `a_borders`.
116108
do
117109
borders := a_borders
110+
ensure
111+
borders_set: borders = a_borders
118112
end
119113

120-
set_padding (a_padding: EG_PADDING)
121-
do
114+
set_padding (a_padding: like padding)
115+
-- Set `padding` with `a_padding`.
116+
do
122117
padding := a_padding
118+
ensure
119+
padding_set: padding = a_padding
123120
end
124121

125-
set_horizontal_alignment (ha: EG_HORIZONTAL_ALIGN)
122+
set_horizontal_alignment (ha: like horizontal_alignment)
123+
-- Set `horizontal_aligment` with `ha`.
126124
do
127125
horizontal_alignment := ha
126+
ensure
127+
horizontal_alignment_set: horizontal_alignment = ha
128128
end
129129

130-
set_vertical_alignment (a_val: EG_VERTICAL_ALIGN)
130+
set_vertical_alignment (a_val: like vertical_alignment)
131+
-- Set `vertical_aligment` with `a_val`.
131132
do
132133
vertical_alignment := a_val
134+
ensure
135+
vertical_alignment_set: vertical_alignment = a_val
133136
end
134137

135-
set_wrap_strategy (a_val: EG_WRAP_STRATEGY)
138+
set_wrap_strategy (a_val: like wrap_strategy)
139+
-- Set `wrap_strategy` with `a_val`.
136140
do
137141
wrap_strategy := a_val
142+
ensure
143+
wrap_strategy_set: wrap_strategy = a_val
138144
end
139145

140-
set_text_direction (a_val: EG_TEXT_DIRECTION)
146+
set_text_direction (a_val: like text_direction)
147+
-- Set `text_direction` with `a_val`
141148
do
142149
text_direction := a_val
150+
ensure
151+
text_direction_set: text_direction = a_val
143152
end
144153

145-
set_text_format (a_val: EG_TEXT_FORMAT)
154+
set_text_format (a_val: like text_format)
155+
-- Set `text_format` with `a_val`.
146156
do
147157
text_format := a_val
158+
ensure
159+
text_format_set: text_format = a_val
148160
end
149161

150-
set_hyperlink_display_type (a_val: EG_HYPERLINK_DISPLAY_TYPE)
162+
set_hyperlink_display_type (a_val: like hyperlink_display_type)
163+
-- Set `hyperlink_display_type` with `a_val`
151164
do
152165
hyperlink_display_type := a_val
166+
ensure
167+
hyperlink_display_type_set: hyperlink_display_type = a_val
153168
end
154169

155-
set_text_rotation (a_val: EG_TEXT_ROTATION)
170+
set_text_rotation (a_val: like text_rotation)
171+
-- Set `text_rotation` with `a_val`
156172
do
157173
text_rotation := a_val
174+
ensure
175+
text_rotation_set: text_rotation = a_val
158176
end
159177

160178
feature -- Eiffel to JSON
@@ -191,12 +209,21 @@ feature -- Eiffel to JSON
191209

192210
do
193211
create Result.make_empty
194-
-- TODO
195212
if attached number_format as l_number_format then
196213
Result.put (l_number_format.to_json, "numberFormat")
197214
end
198-
Result.put (background_color.to_json, "backgroundColor")
199-
Result.put (background_color_style.to_json, "backgroundColorStyle")
215+
if attached background_color as l_bg then
216+
Result.put (l_bg.to_json, "backgroundColor")
217+
end
218+
if attached background_color_style as l_bgs then
219+
Result.put (l_bgs.to_json, "backgroundColorStyle")
220+
end
221+
if attached borders as lb then
222+
Result.put (lb.to_json, "borders")
223+
end
224+
if attached padding as l_padding then
225+
Result.put (l_padding.to_json, "padding")
226+
end
200227

201228
end
202229
end

sheets/src/objects/eg_padding.e

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ note
1212
]"
1313
date: "$Date$"
1414
revision: "$Revision$"
15+
EIS: "name=Padding", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#padding", "protocol=uri"
1516

1617
class
1718
EG_PADDING
@@ -34,23 +35,46 @@ feature -- Access
3435
feature -- Change Element
3536

3637
set_top (a_top: like top)
38+
-- Set `top` with `a_top`.
3739
do
3840
top := a_top
41+
ensure
42+
top_set: top = a_top
3943
end
4044

4145
set_right (a_right: like right)
46+
-- Set `right` with `a_right`.
4247
do
4348
right := a_right
49+
ensure
50+
right_set: right = a_right
4451
end
4552

4653
set_bottom (a_bottom: like bottom)
54+
-- Set `bottom` with `a_bottom`.
4755
do
4856
bottom := a_bottom
57+
ensure
58+
bottom_set: bottom = a_bottom
4959
end
5060

5161
set_left (a_left: like left)
62+
-- Set `left` with `a_left`.
5263
do
5364
left := a_left
65+
ensure
66+
left_set: left = a_left
5467
end
5568

69+
feature -- Eiffel to JSON
70+
71+
to_json: JSON_OBJECT
72+
-- Json representation of current.
73+
do
74+
create Result.make_empty
75+
Result.put (create {JSON_NUMBER}.make_integer (top), "top")
76+
Result.put (create {JSON_NUMBER}.make_integer (right), "right")
77+
Result.put (create {JSON_NUMBER}.make_integer (bottom), "bottom")
78+
Result.put (create {JSON_NUMBER}.make_integer (left), "left")
79+
end
5680
end

0 commit comments

Comments
 (0)