Skip to content

Commit 1c82a5f

Browse files
authored
Merge pull request #11 from jvelilla/eg_sheets
Eg sheets
2 parents f3f0b37 + 29ba448 commit 1c82a5f

13 files changed

+751
-60
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ feature -- Post
4747
end
4848
end
4949

50-
feature -- Get
50+
feature -- Get
5151

5252
get_from_id (a_spreadsheet_id: STRING_8; a_params: detachable EG_SPREADSHEET_PARAMETERS): detachable EG_SPREADSHEET
5353
note
@@ -299,17 +299,19 @@ feature {NONE} -- JSON To Eiffel
299299
-- Create an object `EG_COLOR` from a json rerpesentation `a_json`.
300300
do
301301
create Result
302-
if attached real_value_from_json (a_json, "red") as l_val then
303-
Result.set_red (l_val)
304-
end
305-
if attached real_value_from_json (a_json, "green") as l_val then
306-
Result.set_green (l_val)
307-
end
308-
if attached real_value_from_json (a_json, "blue") as l_val then
309-
Result.set_blue (l_val)
310-
end
311-
if attached real_value_from_json (a_json, "alpha") as l_val then
312-
Result.set_alpha (l_val)
302+
if not a_json.is_empty then
303+
if attached color_value_from_json (a_json, "red") as l_val then
304+
Result.set_red (l_val)
305+
end
306+
if attached color_value_from_json (a_json, "green") as l_val then
307+
Result.set_green (l_val)
308+
end
309+
if attached color_value_from_json (a_json, "blue") as l_val then
310+
Result.set_blue (l_val)
311+
end
312+
if attached color_value_from_json (a_json, "alpha") as l_val then
313+
Result.set_alpha (l_val)
314+
end
313315
end
314316
end
315317

@@ -404,7 +406,9 @@ feature {NONE} -- JSON To Eiffel
404406
Result.set_properties (sheet_properties (l_properties))
405407
end
406408
if attached {JSON_ARRAY} json_value (a_json, "data") as l_data then
407-
-- TODO
409+
across l_data as ic loop
410+
Result.force_data (eg_data_grid (ic.item))
411+
end
408412
end
409413
if attached {JSON_ARRAY} json_value (a_json, "merges") as l_merges then
410414
-- TODO
@@ -441,6 +445,41 @@ feature {NONE} -- JSON To Eiffel
441445
end
442446
end
443447

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+
444483
eg_named_ranges (a_json: JSON_VALUE): EG_NAMED_RANGE
445484
-- Create an object `EG_NAMED_RANGE` from a json representation.
446485
do
@@ -458,6 +497,9 @@ feature {NONE} -- JSON To Eiffel
458497

459498
sheet_properties (a_json: JSON_VALUE): EG_SHEET_PROPERTIES
460499
-- Create an object `EG_SHEET_PROPERTIES` from a json representation `a_json`.
500+
local
501+
l_stype: EG_SHEET_TYPE
502+
l_grid_prop: EG_GRID_PROPERTIES
461503
do
462504
create Result
463505
if attached integer_value_from_json (a_json, "sheetId") as l_sheetId then
@@ -470,19 +512,23 @@ feature {NONE} -- JSON To Eiffel
470512
Result.set_index (l_index)
471513
end
472514
if attached string_value_from_json (a_json, "sheetType") as l_sheet_type then
515+
create l_stype
473516
if l_sheet_type.is_case_insensitive_equal ("GRID") then
474-
Result.sheet_type.set_grid
517+
l_stype.set_grid
475518
elseif l_sheet_type.is_case_insensitive_equal ("OBJECT") then
476-
Result.sheet_type.set_grid
519+
l_stype.set_grid
477520
end
521+
Result.set_sheet_type (l_stype)
478522
end
479523
if attached {JSON_OBJECT} json_value (a_json, "gridProperties") as l_grid_properties then
524+
create l_grid_prop
480525
if attached integer_value_from_json (l_grid_properties, "rowCount") as l_row_count then
481-
Result.grid_properties.set_row_count (l_row_count)
526+
l_grid_prop.set_row_count (l_row_count)
482527
end
483528
if attached integer_value_from_json (l_grid_properties, "columnCount") as l_column_count then
484-
Result.grid_properties.set_column_count (l_column_count)
529+
l_grid_prop.set_column_count (l_column_count)
485530
end
531+
Result.set_grid_properties (l_grid_prop)
486532
end
487533
if attached boolean_value_from_json (a_json, "hidden") as l_hidden then
488534
Result.set_hidden (l_hidden)
@@ -638,6 +684,21 @@ feature {NONE} -- Implementation
638684
end
639685
end
640686

687+
color_value_from_json (a_json_data: detachable JSON_VALUE; a_id: STRING): REAL
688+
do
689+
if
690+
attached {JSON_NUMBER} json_value (a_json_data, a_id) as v and then
691+
v.numeric_type = v.real_type
692+
then
693+
Result := v.item.to_real
694+
elseif attached {JSON_NUMBER} json_value (a_json_data, a_id) as v and then
695+
v.numeric_type = v.integer_type
696+
then
697+
Result := v.item.to_integer
698+
end
699+
700+
end
701+
641702
integer_value_from_json (a_json_data: detachable JSON_VALUE; a_id: STRING): INTEGER
642703
do
643704
if

sheets/src/objects/eg_cell_data.e

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
note
2+
description: "[
3+
Data about a specific cell.
4+
5+
{
6+
"userEnteredValue": {
7+
object (ExtendedValue)
8+
},
9+
"effectiveValue": {
10+
object (ExtendedValue)
11+
},
12+
"formattedValue": string,
13+
"userEnteredFormat": {
14+
object (CellFormat)
15+
},
16+
"effectiveFormat": {
17+
object (CellFormat)
18+
},
19+
"hyperlink": string,
20+
"note": string,
21+
"textFormatRuns": [
22+
{
23+
object (TextFormatRun)
24+
}
25+
],
26+
"dataValidation": {
27+
object (DataValidationRule)
28+
},
29+
"pivotTable": {
30+
object (PivotTable)
31+
}
32+
}
33+
]"
34+
date: "$Date$"
35+
revision: "$Revision$"
36+
EIS: "name=CellData", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellData", "protocol=uri"
37+
38+
class
39+
EG_CELL_DATA
40+
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+
55+
end

sheets/src/objects/eg_color.e

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ note
1818
class
1919
EG_COLOR
2020

21+
inherit
22+
23+
ANY
24+
redefine
25+
default_create
26+
end
27+
28+
create
29+
default_create
30+
31+
feature {NONE} -- Initialization
32+
33+
default_create
34+
do
35+
is_default := True
36+
end
2137

2238
feature -- Access
2339

@@ -37,47 +53,73 @@ feature -- Access
3753
-- 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.
3854
-- 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).
3955

56+
is_default: BOOLEAN
57+
-- Are the attributes in default values?
58+
4059

4160
feature -- Element Change
4261

4362
set_red (a_val: REAL)
63+
-- Set `red` to `a_val`.
4464
do
65+
is_default := False
4566
red := a_val
4667
ensure
68+
not_default: not is_default
4769
red_set: red = a_val
4870
end
4971

5072
set_green (a_val: REAL)
5173
do
74+
is_default := False
5275
green := a_val
5376
ensure
77+
not_default: not is_default
5478
green_set: green = a_val
5579
end
5680

5781
set_blue (a_val: REAL)
5882
do
83+
is_default := False
5984
blue := a_val
6085
ensure
86+
not_default: not is_default
6187
blue_set: blue = a_val
6288
end
6389

6490
set_alpha (a_val: REAL)
6591
do
92+
is_default := False
6693
alpha := a_val
6794
ensure
95+
not_default: not is_default
6896
alpha_set: alpha = a_val
6997
end
7098

99+
reset
100+
-- Reset the attributes to default values.
101+
do
102+
is_default := True
103+
red := 0
104+
green := 0
105+
blue := 0
106+
alpha := 0
107+
end
108+
71109
feature -- Eiffel to JSON
72110

73111
to_json: JSON_OBJECT
74112
-- Json representation of current object.
75113
do
76-
create Result.make_with_capacity (4)
77-
Result.put (create {JSON_NUMBER}.make_real (red), "red")
78-
Result.put (create {JSON_NUMBER}.make_real (green), "green")
79-
Result.put (create {JSON_NUMBER}.make_real (blue), "blue")
80-
Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha")
114+
if is_default then
115+
create Result.make
116+
else
117+
create Result.make_with_capacity (4)
118+
Result.put (create {JSON_NUMBER}.make_real (red), "red")
119+
Result.put (create {JSON_NUMBER}.make_real (green), "green")
120+
Result.put (create {JSON_NUMBER}.make_real (blue), "blue")
121+
Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha")
122+
end
81123
end
82124

83125
invariant

0 commit comments

Comments
 (0)