Skip to content

Commit 24c61d3

Browse files
committed
Updated EG_SPREADSHEET_PROPERTIES class
defined all the attributes as detachable, and update to_json feature.
1 parent a899c75 commit 24c61d3

File tree

2 files changed

+51
-58
lines changed

2 files changed

+51
-58
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ feature {NONE} -- JSON To Eiffel
111111
-- Create an object `EG_SPREADSHEET_PROPERTIES` from a json representation `a_json`.
112112
local
113113
l_cell_format: EG_CELL_FORMAT
114+
l_ri: EG_RECALCULATION_INTERVAL
114115
do
115116
create Result
116117
if attached string_value_from_json (a_json, "title") as l_title then
@@ -120,13 +121,15 @@ feature {NONE} -- JSON To Eiffel
120121
Result.set_locale (l_locale)
121122
end
122123
if attached string_value_from_json (a_json, "autoRecalc") as l_auto_recalc then
124+
create l_ri
123125
if l_auto_recalc.is_case_insensitive_equal ("ON_CHANGE") then
124-
Result.auto_recalc.set_on_change
126+
l_ri.set_on_change
125127
elseif l_auto_recalc.is_case_insensitive_equal ("MINUTE") then
126-
Result.auto_recalc.set_minute
128+
l_ri.set_minute
127129
elseif l_auto_recalc.is_case_insensitive_equal ("HOUR") then
128-
Result.auto_recalc.set_hour
130+
l_ri.set_hour
129131
end
132+
Result.set_auto_recalc (l_ri)
130133
end
131134
if attached string_value_from_json (a_json, "timeZone") as l_time_zone then
132135
Result.set_time_zone (l_time_zone)

sheets/src/objects/eg_spreadsheet_properties.e

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -27,129 +27,119 @@ note
2727
class
2828
EG_SPREADSHEET_PROPERTIES
2929

30-
inherit
31-
ANY
32-
redefine
33-
default_create
34-
end
35-
create
36-
default_create
37-
38-
feature {NONE} -- Initialization
39-
40-
default_create
41-
do
42-
create title.make_empty
43-
create locale.make_empty
44-
create auto_recalc
45-
create time_zone.make_empty
46-
create default_format
47-
create spreadsheet_theme
48-
create iterative_calculation_settings
49-
end
5030

5131
feature -- Access
5232

53-
title: STRING
33+
title: detachable STRING
5434
-- The title of the spreadsheet.
5535

56-
locale: STRING
36+
locale: detachable STRING
5737
-- The locale of the spreadsheet in one of the following formats:
5838
-- an ISO 639-1 language code such as en
5939
-- an ISO 639-2 language code such as fil, if no 639-1 code exists
6040
-- a combination of the ISO language code and country code, such as en_US
6141
-- Note: when updating this field, not all locales/languages are supported.
6242

63-
auto_recalc: EG_RECALCULATION_INTERVAL
43+
auto_recalc: detachable EG_RECALCULATION_INTERVAL
6444
-- The amount of time to wait before volatile functions are recalculated.
6545

66-
time_zone: STRING
46+
time_zone: detachable STRING
6747
-- The time zone of the spreadsheet, in CLDR format such as America/New_York.
6848
-- If the time zone isn't recognized, this may be a custom time zone such as GMT-07:00.
6949

70-
default_format: EG_CELL_FORMAT
50+
default_format: detachable EG_CELL_FORMAT
7151
-- The default format of all cells in the spreadsheet.
7252
-- CellData.effectiveFormat will not be set if the cell's format is equal to this default format. This field is read-only.
7353

7454
iterative_calculation_settings: detachable EG_ITERATIVE_CALCULATION_SETTINGS
7555
-- Determines whether and how circular references are resolved with iterative calculation.
7656
-- Absence of this field means that circular references result in calculation errors.
7757

78-
spreadsheet_theme: EG_SPREADSHEET_THEME
58+
spreadsheet_theme: detachable EG_SPREADSHEET_THEME
7959
-- theme applied to the spreadsheet.
8060

8161
feature -- Element Change
8262

83-
set_title (a_title: STRING)
63+
set_title (a_title: like title)
8464
-- Set `title` with `a_title`.
8565
do
8666
title := a_title
8767
ensure
8868
title_set: title = a_title
8969
end
9070

91-
set_locale (a_locale: STRING)
71+
set_locale (a_locale: like locale)
9272
-- Set `locale` with `a_locale`.
9373
do
9474
locale := a_locale
9575
ensure
9676
locale_set: locale = a_locale
9777
end
9878

99-
set_time_zone (a_time_zone: STRING)
79+
set_time_zone (a_time_zone: like time_zone)
10080
-- Set `time_zone` with `a_time_zone`
10181
do
10282
time_zone := a_time_zone
83+
ensure
84+
time_zone_set: time_zone = a_time_zone
10385
end
10486

105-
set_default_format (a_format: EG_CELL_FORMAT)
87+
set_default_format (a_format: like default_format)
10688
-- Set `default_format` with `format`.
10789
do
10890
default_format := a_format
91+
ensure
92+
default_format_set: default_format = a_format
10993
end
11094

11195
set_iterative_calculation_settings (a_iterative_calculation_settings: like iterative_calculation_settings)
11296
-- Set `iterative_calculation_settings` with `a_iterative_calculation_settings`.
11397
do
11498
iterative_calculation_settings := a_iterative_calculation_settings
99+
ensure
100+
iterative_calculation_settings_set: iterative_calculation_settings = a_iterative_calculation_settings
115101
end
116102

117-
set_spreadsheet_theme (a_theme: EG_SPREADSHEET_THEME)
103+
set_spreadsheet_theme (a_theme: like spreadsheet_theme)
118104
do
119105
spreadsheet_theme := a_theme
106+
ensure
107+
spreadsheet_theme_set: spreadsheet_theme = a_theme
108+
end
109+
110+
set_auto_recalc (a_auto_recalc: like auto_recalc)
111+
-- Set auto_recalc with `a_auto_recalc`.
112+
do
113+
auto_recalc := a_auto_recalc
114+
ensure
115+
auto_recalc_set: auto_recalc = a_auto_recalc
120116
end
121117

118+
122119
feature -- Eiffel to JSON
123120

124121
to_json: JSON_OBJECT
125122
-- Json representation of the current object
126-
-- {
127-
-- "title": string,
128-
-- "locale": string,
129-
-- "autoRecalc": enum (RecalculationInterval),
130-
-- "timeZone": string,
131-
-- "defaultFormat": {
132-
-- object (CellFormat)
133-
-- },
134-
-- "iterativeCalculationSettings": {
135-
-- object (IterativeCalculationSettings)
136-
-- },
137-
-- "spreadsheetTheme": {
138-
-- object (SpreadsheetTheme)
139-
-- }
140-
-- }
141123
do
142-
create Result.make_with_capacity (5)
143-
Result.put (create {JSON_STRING}.make_from_string (title), "title")
144-
Result.put (create {JSON_STRING}.make_from_string (locale), "locale")
145-
Result.put (auto_recalc.to_json, "autoRecalc")
146-
Result.put (create {JSON_STRING}.make_from_string (time_zone), "timeZone")
147-
Result.put (default_format.to_json, "defaultFormat")
124+
create Result.make_empty
125+
if attached title as l_title then
126+
Result.put (create {JSON_STRING}.make_from_string (l_title), "title")
127+
end
128+
if attached locale as l_locale then
129+
Result.put (create {JSON_STRING}.make_from_string (l_locale), "locale")
130+
end
131+
if attached auto_recalc as l_auto_recalc then
132+
Result.put (l_auto_recalc.to_json, "autoRecalc")
133+
end
134+
if attached time_zone as l_time_zone then
135+
Result.put (create {JSON_STRING}.make_from_string (l_time_zone), "timeZone")
136+
end
148137
if attached iterative_calculation_settings as l_ics then
149-
Result.put (default_format.to_json, "iterativeCalculationSettings")
138+
Result.put (l_ics.to_json, "iterativeCalculationSettings")
139+
end
140+
if attached spreadsheet_theme as l_sp then
141+
Result.put (l_sp.to_json, "spreadsheetTheme")
150142
end
151-
Result.put (spreadsheet_theme.to_json, "spreadsheetTheme")
152-
153143
end
154144

155145
end

0 commit comments

Comments
 (0)