Skip to content

Commit 29ba448

Browse files
committed
Added new classes to represent error values and extended values
Updated Eiffel to JSON mapping.
1 parent 022b18e commit 29ba448

File tree

8 files changed

+331
-16
lines changed

8 files changed

+331
-16
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ feature {NONE} -- JSON To Eiffel
406406
Result.set_properties (sheet_properties (l_properties))
407407
end
408408
if attached {JSON_ARRAY} json_value (a_json, "data") as l_data then
409-
-- TODO
409+
across l_data as ic loop
410+
Result.force_data (eg_data_grid (ic.item))
411+
end
410412
end
411413
if attached {JSON_ARRAY} json_value (a_json, "merges") as l_merges then
412414
-- TODO
@@ -443,6 +445,41 @@ feature {NONE} -- JSON To Eiffel
443445
end
444446
end
445447

448+
eg_data_grid (a_json: JSON_VALUE): EG_GRID_DATA
449+
-- Create an object `EG_GRID_DATA` from a json representation.
450+
do
451+
create Result
452+
if attached integer_value_from_json (a_json, "startRow") as l_val then
453+
Result.set_start_row (l_val)
454+
end
455+
if attached integer_value_from_json (a_json, "startColumn") as l_val then
456+
Result.set_start_column (l_val)
457+
end
458+
if attached {JSON_ARRAY} json_value (a_json, "rowData") as l_data then
459+
across l_data as ic loop
460+
Result.force_row_data (eg_row_data (ic.item))
461+
end
462+
end
463+
end
464+
465+
eg_row_data (a_json: JSON_VALUE): EG_ROW_DATA
466+
-- Create an object `EG_ROW_DATA` from a json representation.
467+
do
468+
create Result
469+
if attached {JSON_ARRAY} json_value (a_json, "values") as l_data then
470+
across l_data as ic loop
471+
Result.force_value(eg_cell_data (ic.item))
472+
end
473+
end
474+
end
475+
476+
eg_cell_data (a_json: JSON_VALUE): EG_CELL_DATA
477+
-- Create an object `EG_CELL_DATA` from a json representation.
478+
do
479+
create Result
480+
481+
end
482+
446483
eg_named_ranges (a_json: JSON_VALUE): EG_NAMED_RANGE
447484
-- Create an object `EG_NAMED_RANGE` from a json representation.
448485
do

sheets/src/objects/eg_cell_data.e

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,18 @@ note
3838
class
3939
EG_CELL_DATA
4040

41+
feature -- Access
42+
43+
user_entered_value: detachable EG_EXTENDED_VALUE
44+
45+
feature -- Element Change
46+
47+
feature -- Eiffel to JSON
48+
49+
to_json: JSON_OBJECT
50+
-- JSON representation of the current object.
51+
do
52+
create Result.make_empty
53+
end
54+
4155
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
note
2+
description: "[
3+
An error in a cell.
4+
5+
JSON representation
6+
7+
{
8+
"type": enum (ErrorType),
9+
"message": string
10+
}
11+
12+
]"
13+
date: "$Date$"
14+
revision: "$Revision$"
15+
EIS: "name= Error Value", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ErrorValue", "protocol=uri"
16+
17+
class
18+
EG_ERROR_VALUE
19+
20+
end
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
note
2+
description: "[
3+
4+
The kinds of value that a cell in a spreadsheet can have.
5+
{
6+
7+
// Union field value can be only one of the following:
8+
"numberValue": number,
9+
"stringValue": string,
10+
"boolValue": boolean,
11+
"formulaValue": string,
12+
"errorValue": {
13+
object (ErrorValue)
14+
}
15+
// End of list of possible types for union field value.
16+
}
17+
18+
]"
19+
date: "$Date$"
20+
revision: "$Revision$"
21+
22+
class
23+
EG_EXTENDED_VALUE
24+
25+
26+
feature -- Access
27+
28+
number_value: REAL
29+
-- Represents a double value.
30+
-- Note: Dates, Times and DateTimes are represented as doubles in "serial number" format.
31+
32+
string_value: detachable STRING
33+
-- Represents a string value. Leading single quotes are not included.
34+
-- For example, if the user typed '123 into the UI, this would be represented as a stringValue of "123".
35+
36+
bool_value: BOOLEAN
37+
-- Represents a boolean value.
38+
39+
formula_value: detachable STRING
40+
-- Represents a formula.
41+
42+
error_value: detachable EG_ERROR_VALUE
43+
-- Represents an error. This field is read-only.
44+
45+
feature -- Status Report
46+
47+
is_number_value: BOOLEAN
48+
-- Is the current value a number?
49+
50+
is_string_value: BOOLEAN
51+
-- Is the current value an string?
52+
53+
is_bool_value: BOOLEAN
54+
-- Is the current value a boolean?
55+
56+
is_formula_value: BOOLEAN
57+
-- Is the current value a formula?
58+
59+
is_error_value: BOOLEAN
60+
-- Is the current value an error value?
61+
62+
feature -- Element Change
63+
64+
set_number_value (a_value: like number_value)
65+
-- Set `number_value` with `a_vaue`?
66+
do
67+
is_number_value := True
68+
is_string_value := False
69+
is_bool_value := False
70+
is_formula_value:= False
71+
is_error_value := False
72+
73+
number_value := a_value
74+
ensure
75+
number_value_set: number_value = a_value
76+
union_field_number: is_number_value implies
77+
( is_string_value = False and then is_bool_value = False and then is_formula_value = False and then is_error_value = False)
78+
end
79+
80+
set_string_value (a_value: like string_value)
81+
-- Set `string_value` with `a_vaue`?
82+
do
83+
is_number_value := False
84+
is_string_value := True
85+
is_bool_value := False
86+
is_formula_value:= False
87+
is_error_value := False
88+
89+
string_value := a_value
90+
ensure
91+
string_value_set: string_value = a_value
92+
union_field_string: is_string_value implies
93+
( is_number_value = False and then is_bool_value = False and then is_formula_value = False and then is_error_value = False)
94+
end
95+
96+
end

sheets/src/objects/eg_grid_data.e

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ feature -- Element Change
6868
start_column_set: start_column = a_val
6969
end
7070

71-
force_raw_data (a_data: EG_ROW_DATA)
71+
force_row_data (a_data: EG_ROW_DATA)
7272
-- Add an item `a_data` to the list of `row_data`
7373
local
7474
l_row_data: like row_data
@@ -83,6 +83,14 @@ feature -- Element Change
8383
row_data := l_row_data
8484
end
8585

86+
set_row_data (a_data: like row_data)
87+
-- Set `row_data` with `a_data`.
88+
do
89+
row_data := a_data
90+
ensure
91+
row_data_set: row_data = a_data
92+
end
93+
8694
force_row_metadata (a_metadata: EG_DIMENSION_PROPERTIES)
8795
-- Add an item `a_metadata` to the list of `row_metadata`
8896
local
@@ -98,6 +106,14 @@ feature -- Element Change
98106
row_metadata := l_row_metadata
99107
end
100108

109+
set_row_metadata (a_data: like row_metadata)
110+
-- Set `row_metadata` with `a_data`.
111+
do
112+
row_metadata := a_data
113+
ensure
114+
row_metadata_set: row_metadata = a_data
115+
end
116+
101117

102118
force_column_metadata (a_metadata: EG_DIMENSION_PROPERTIES)
103119
-- Add an item `a_metadata` to the list of `column_metadata`
@@ -114,10 +130,45 @@ feature -- Element Change
114130
column_metadata := l_column_metadata
115131
end
116132

133+
set_column_metadata (a_data: like column_metadata)
134+
-- Set `column_metadata` with `a_data`.
135+
do
136+
column_metadata := a_data
137+
ensure
138+
column_metadata_set: column_metadata = a_data
139+
end
140+
117141
feature -- Eiffel to JSON
118142

119143
to_json: JSON_OBJECT
144+
--Json representation of the current object.
145+
local
146+
j_array: JSON_ARRAY
120147
do
121-
create Result.make
148+
create Result.make_empty
149+
Result.put (create {JSON_NUMBER}.make_integer (start_row), "startRow")
150+
Result.put (create {JSON_NUMBER}.make_integer (start_column), "startColumn")
151+
if attached row_data as l_rd then
152+
create j_array.make (l_rd.count)
153+
across l_rd as ic loop
154+
j_array.add (ic.item.to_json)
155+
end
156+
Result.put (j_array, "rowData")
157+
end
158+
if attached row_metadata as l_rm then
159+
create j_array.make (l_rm.count)
160+
across l_rm as ic loop
161+
j_array.add (ic.item.to_json)
162+
end
163+
Result.put (j_array, "rowMetadata")
164+
end
165+
if attached column_metadata as l_cm then
166+
create j_array.make (l_cm.count)
167+
across l_cm as ic loop
168+
j_array.add (ic.item.to_json)
169+
end
170+
Result.put (j_array, "columnMetadata")
171+
end
172+
122173
end
123174
end

sheets/src/objects/eg_row_data.e

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,46 @@ note
1515

1616
class
1717
EG_ROW_DATA
18-
19-
18+
19+
2020
feature -- Access
21-
22-
values: detachable LIST [EG_CELL_DATA]
21+
22+
values: detachable LIST [EG_CELL_DATA]
2323
-- The values in the row, one per column.
2424

25+
26+
feature -- Element Change
27+
28+
force_value (a_data: EG_CELL_DATA)
29+
-- Add an item `a_data` to the list of `values`.
30+
local
31+
l_values: like values
32+
do
33+
l_values := values
34+
if l_values /= Void then
35+
l_values.force (a_data)
36+
else
37+
create {ARRAYED_LIST [EG_CELL_DATA]} l_values.make (5)
38+
l_values.force (a_data)
39+
end
40+
values := l_values
41+
end
42+
43+
44+
feature -- Eiffel to JSON
45+
46+
to_json: JSON_OBJECT
47+
-- Json representation of the current object.
48+
local
49+
j_array: JSON_ARRAY
50+
do
51+
create Result.make_empty
52+
if attached values as l_values then
53+
create j_array.make (l_values.count)
54+
across l_values as ic loop
55+
j_array.add (ic.item.to_json)
56+
end
57+
Result.put (j_array, "values")
58+
end
59+
end
2560
end

sheets/src/objects/eg_sheet.e

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,66 @@ feature -- Eiffel to JSON
395395
end
396396

397397
end
398+
399+
-- "data": [
400+
-- {
401+
-- object (GridData)
402+
-- }
403+
-- ],
404+
-- "merges": [
405+
-- {
406+
-- object (GridRange)
407+
-- }
408+
-- ],
409+
-- "conditionalFormats": [
410+
-- {
411+
-- object (ConditionalFormatRule)
412+
-- }
413+
-- ],
414+
-- "filterViews": [
415+
-- {
416+
-- object (FilterView)
417+
-- }
418+
-- ],
419+
-- "protectedRanges": [
420+
-- {
421+
-- object (ProtectedRange)
422+
-- }
423+
-- ],
424+
-- "basicFilter": {
425+
-- object (BasicFilter)
426+
-- },
427+
-- "charts": [
428+
-- {
429+
-- object (EmbeddedChart)
430+
-- }
431+
-- ],
432+
-- "bandedRanges": [
433+
-- {
434+
-- object (BandedRange)
435+
-- }
436+
-- ],
437+
-- "developerMetadata": [
438+
-- {
439+
-- object (DeveloperMetadata)
440+
-- }
441+
-- ],
442+
-- "rowGroups": [
443+
-- {
444+
-- object (DimensionGroup)
445+
-- }
446+
-- ],
447+
-- "columnGroups": [
448+
-- {
449+
-- object (DimensionGroup)
450+
-- }
451+
-- ],
452+
-- "slicers": [
453+
-- {
454+
-- object (Slicer)
455+
-- }
456+
-- ]
457+
-- }
458+
459+
398460
end

0 commit comments

Comments
 (0)