Skip to content

Commit

Permalink
Added new classes to represent error values and extended values
Browse files Browse the repository at this point in the history
Updated Eiffel to JSON mapping.
  • Loading branch information
jvelilla committed Sep 7, 2020
1 parent 022b18e commit 29ba448
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 16 deletions.
39 changes: 38 additions & 1 deletion sheets/src/json/eg_sheets_json.e
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ feature {NONE} -- JSON To Eiffel
Result.set_properties (sheet_properties (l_properties))
end
if attached {JSON_ARRAY} json_value (a_json, "data") as l_data then
-- TODO
across l_data as ic loop
Result.force_data (eg_data_grid (ic.item))
end
end
if attached {JSON_ARRAY} json_value (a_json, "merges") as l_merges then
-- TODO
Expand Down Expand Up @@ -443,6 +445,41 @@ feature {NONE} -- JSON To Eiffel
end
end

eg_data_grid (a_json: JSON_VALUE): EG_GRID_DATA
-- Create an object `EG_GRID_DATA` from a json representation.
do
create Result
if attached integer_value_from_json (a_json, "startRow") as l_val then
Result.set_start_row (l_val)
end
if attached integer_value_from_json (a_json, "startColumn") as l_val then
Result.set_start_column (l_val)
end
if attached {JSON_ARRAY} json_value (a_json, "rowData") as l_data then
across l_data as ic loop
Result.force_row_data (eg_row_data (ic.item))
end
end
end

eg_row_data (a_json: JSON_VALUE): EG_ROW_DATA
-- Create an object `EG_ROW_DATA` from a json representation.
do
create Result
if attached {JSON_ARRAY} json_value (a_json, "values") as l_data then
across l_data as ic loop
Result.force_value(eg_cell_data (ic.item))
end
end
end

eg_cell_data (a_json: JSON_VALUE): EG_CELL_DATA
-- Create an object `EG_CELL_DATA` from a json representation.
do
create Result

end

eg_named_ranges (a_json: JSON_VALUE): EG_NAMED_RANGE
-- Create an object `EG_NAMED_RANGE` from a json representation.
do
Expand Down
14 changes: 14 additions & 0 deletions sheets/src/objects/eg_cell_data.e
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ note
class
EG_CELL_DATA

feature -- Access

user_entered_value: detachable EG_EXTENDED_VALUE

feature -- Element Change

feature -- Eiffel to JSON

to_json: JSON_OBJECT
-- JSON representation of the current object.
do
create Result.make_empty
end

end
20 changes: 20 additions & 0 deletions sheets/src/objects/eg_error_value.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
note
description: "[
An error in a cell.
JSON representation
{
"type": enum (ErrorType),
"message": string
}
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name= Error Value", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ErrorValue", "protocol=uri"

class
EG_ERROR_VALUE

end
96 changes: 96 additions & 0 deletions sheets/src/objects/eg_extended_value.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
note
description: "[
The kinds of value that a cell in a spreadsheet can have.
{
// Union field value can be only one of the following:
"numberValue": number,
"stringValue": string,
"boolValue": boolean,
"formulaValue": string,
"errorValue": {
object (ErrorValue)
}
// End of list of possible types for union field value.
}
]"
date: "$Date$"
revision: "$Revision$"

class
EG_EXTENDED_VALUE


feature -- Access

number_value: REAL
-- Represents a double value.
-- Note: Dates, Times and DateTimes are represented as doubles in "serial number" format.

string_value: detachable STRING
-- Represents a string value. Leading single quotes are not included.
-- For example, if the user typed '123 into the UI, this would be represented as a stringValue of "123".

bool_value: BOOLEAN
-- Represents a boolean value.

formula_value: detachable STRING
-- Represents a formula.

error_value: detachable EG_ERROR_VALUE
-- Represents an error. This field is read-only.

feature -- Status Report

is_number_value: BOOLEAN
-- Is the current value a number?

is_string_value: BOOLEAN
-- Is the current value an string?

is_bool_value: BOOLEAN
-- Is the current value a boolean?

is_formula_value: BOOLEAN
-- Is the current value a formula?

is_error_value: BOOLEAN
-- Is the current value an error value?

feature -- Element Change

set_number_value (a_value: like number_value)
-- Set `number_value` with `a_vaue`?
do
is_number_value := True
is_string_value := False
is_bool_value := False
is_formula_value:= False
is_error_value := False

number_value := a_value
ensure
number_value_set: number_value = a_value
union_field_number: is_number_value implies
( is_string_value = False and then is_bool_value = False and then is_formula_value = False and then is_error_value = False)
end

set_string_value (a_value: like string_value)
-- Set `string_value` with `a_vaue`?
do
is_number_value := False
is_string_value := True
is_bool_value := False
is_formula_value:= False
is_error_value := False

string_value := a_value
ensure
string_value_set: string_value = a_value
union_field_string: is_string_value implies
( is_number_value = False and then is_bool_value = False and then is_formula_value = False and then is_error_value = False)
end

end
55 changes: 53 additions & 2 deletions sheets/src/objects/eg_grid_data.e
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ feature -- Element Change
start_column_set: start_column = a_val
end

force_raw_data (a_data: EG_ROW_DATA)
force_row_data (a_data: EG_ROW_DATA)
-- Add an item `a_data` to the list of `row_data`
local
l_row_data: like row_data
Expand All @@ -83,6 +83,14 @@ feature -- Element Change
row_data := l_row_data
end

set_row_data (a_data: like row_data)
-- Set `row_data` with `a_data`.
do
row_data := a_data
ensure
row_data_set: row_data = a_data
end

force_row_metadata (a_metadata: EG_DIMENSION_PROPERTIES)
-- Add an item `a_metadata` to the list of `row_metadata`
local
Expand All @@ -98,6 +106,14 @@ feature -- Element Change
row_metadata := l_row_metadata
end

set_row_metadata (a_data: like row_metadata)
-- Set `row_metadata` with `a_data`.
do
row_metadata := a_data
ensure
row_metadata_set: row_metadata = a_data
end


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

set_column_metadata (a_data: like column_metadata)
-- Set `column_metadata` with `a_data`.
do
column_metadata := a_data
ensure
column_metadata_set: column_metadata = a_data
end

feature -- Eiffel to JSON

to_json: JSON_OBJECT
--Json representation of the current object.
local
j_array: JSON_ARRAY
do
create Result.make
create Result.make_empty
Result.put (create {JSON_NUMBER}.make_integer (start_row), "startRow")
Result.put (create {JSON_NUMBER}.make_integer (start_column), "startColumn")
if attached row_data as l_rd then
create j_array.make (l_rd.count)
across l_rd as ic loop
j_array.add (ic.item.to_json)
end
Result.put (j_array, "rowData")
end
if attached row_metadata as l_rm then
create j_array.make (l_rm.count)
across l_rm as ic loop
j_array.add (ic.item.to_json)
end
Result.put (j_array, "rowMetadata")
end
if attached column_metadata as l_cm then
create j_array.make (l_cm.count)
across l_cm as ic loop
j_array.add (ic.item.to_json)
end
Result.put (j_array, "columnMetadata")
end

end
end
43 changes: 39 additions & 4 deletions sheets/src/objects/eg_row_data.e
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,46 @@ note

class
EG_ROW_DATA


feature -- Access
values: detachable LIST [EG_CELL_DATA]

values: detachable LIST [EG_CELL_DATA]
-- The values in the row, one per column.


feature -- Element Change

force_value (a_data: EG_CELL_DATA)
-- Add an item `a_data` to the list of `values`.
local
l_values: like values
do
l_values := values
if l_values /= Void then
l_values.force (a_data)
else
create {ARRAYED_LIST [EG_CELL_DATA]} l_values.make (5)
l_values.force (a_data)
end
values := l_values
end


feature -- Eiffel to JSON

to_json: JSON_OBJECT
-- Json representation of the current object.
local
j_array: JSON_ARRAY
do
create Result.make_empty
if attached values as l_values then
create j_array.make (l_values.count)
across l_values as ic loop
j_array.add (ic.item.to_json)
end
Result.put (j_array, "values")
end
end
end
62 changes: 62 additions & 0 deletions sheets/src/objects/eg_sheet.e
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,66 @@ feature -- Eiffel to JSON
end

end

-- "data": [
-- {
-- object (GridData)
-- }
-- ],
-- "merges": [
-- {
-- object (GridRange)
-- }
-- ],
-- "conditionalFormats": [
-- {
-- object (ConditionalFormatRule)
-- }
-- ],
-- "filterViews": [
-- {
-- object (FilterView)
-- }
-- ],
-- "protectedRanges": [
-- {
-- object (ProtectedRange)
-- }
-- ],
-- "basicFilter": {
-- object (BasicFilter)
-- },
-- "charts": [
-- {
-- object (EmbeddedChart)
-- }
-- ],
-- "bandedRanges": [
-- {
-- object (BandedRange)
-- }
-- ],
-- "developerMetadata": [
-- {
-- object (DeveloperMetadata)
-- }
-- ],
-- "rowGroups": [
-- {
-- object (DimensionGroup)
-- }
-- ],
-- "columnGroups": [
-- {
-- object (DimensionGroup)
-- }
-- ],
-- "slicers": [
-- {
-- object (Slicer)
-- }
-- ]
-- }


end
Loading

0 comments on commit 29ba448

Please sign in to comment.