Skip to content

Commit

Permalink
Merge pull request #11 from jvelilla/eg_sheets
Browse files Browse the repository at this point in the history
Eg sheets
  • Loading branch information
jvelilla authored Sep 7, 2020
2 parents f3f0b37 + 29ba448 commit 1c82a5f
Show file tree
Hide file tree
Showing 13 changed files with 751 additions and 60 deletions.
95 changes: 78 additions & 17 deletions sheets/src/json/eg_sheets_json.e
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ feature -- Post
end
end

feature -- Get
feature -- Get

get_from_id (a_spreadsheet_id: STRING_8; a_params: detachable EG_SPREADSHEET_PARAMETERS): detachable EG_SPREADSHEET
note
Expand Down Expand Up @@ -299,17 +299,19 @@ feature {NONE} -- JSON To Eiffel
-- Create an object `EG_COLOR` from a json rerpesentation `a_json`.
do
create Result
if attached real_value_from_json (a_json, "red") as l_val then
Result.set_red (l_val)
end
if attached real_value_from_json (a_json, "green") as l_val then
Result.set_green (l_val)
end
if attached real_value_from_json (a_json, "blue") as l_val then
Result.set_blue (l_val)
end
if attached real_value_from_json (a_json, "alpha") as l_val then
Result.set_alpha (l_val)
if not a_json.is_empty then
if attached color_value_from_json (a_json, "red") as l_val then
Result.set_red (l_val)
end
if attached color_value_from_json (a_json, "green") as l_val then
Result.set_green (l_val)
end
if attached color_value_from_json (a_json, "blue") as l_val then
Result.set_blue (l_val)
end
if attached color_value_from_json (a_json, "alpha") as l_val then
Result.set_alpha (l_val)
end
end
end

Expand Down Expand Up @@ -404,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 @@ -441,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 All @@ -458,6 +497,9 @@ feature {NONE} -- JSON To Eiffel

sheet_properties (a_json: JSON_VALUE): EG_SHEET_PROPERTIES
-- Create an object `EG_SHEET_PROPERTIES` from a json representation `a_json`.
local
l_stype: EG_SHEET_TYPE
l_grid_prop: EG_GRID_PROPERTIES
do
create Result
if attached integer_value_from_json (a_json, "sheetId") as l_sheetId then
Expand All @@ -470,19 +512,23 @@ feature {NONE} -- JSON To Eiffel
Result.set_index (l_index)
end
if attached string_value_from_json (a_json, "sheetType") as l_sheet_type then
create l_stype
if l_sheet_type.is_case_insensitive_equal ("GRID") then
Result.sheet_type.set_grid
l_stype.set_grid
elseif l_sheet_type.is_case_insensitive_equal ("OBJECT") then
Result.sheet_type.set_grid
l_stype.set_grid
end
Result.set_sheet_type (l_stype)
end
if attached {JSON_OBJECT} json_value (a_json, "gridProperties") as l_grid_properties then
create l_grid_prop
if attached integer_value_from_json (l_grid_properties, "rowCount") as l_row_count then
Result.grid_properties.set_row_count (l_row_count)
l_grid_prop.set_row_count (l_row_count)
end
if attached integer_value_from_json (l_grid_properties, "columnCount") as l_column_count then
Result.grid_properties.set_column_count (l_column_count)
l_grid_prop.set_column_count (l_column_count)
end
Result.set_grid_properties (l_grid_prop)
end
if attached boolean_value_from_json (a_json, "hidden") as l_hidden then
Result.set_hidden (l_hidden)
Expand Down Expand Up @@ -638,6 +684,21 @@ feature {NONE} -- Implementation
end
end

color_value_from_json (a_json_data: detachable JSON_VALUE; a_id: STRING): REAL
do
if
attached {JSON_NUMBER} json_value (a_json_data, a_id) as v and then
v.numeric_type = v.real_type
then
Result := v.item.to_real
elseif attached {JSON_NUMBER} json_value (a_json_data, a_id) as v and then
v.numeric_type = v.integer_type
then
Result := v.item.to_integer
end

end

integer_value_from_json (a_json_data: detachable JSON_VALUE; a_id: STRING): INTEGER
do
if
Expand Down
55 changes: 55 additions & 0 deletions sheets/src/objects/eg_cell_data.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
note
description: "[
Data about a specific cell.
{
"userEnteredValue": {
object (ExtendedValue)
},
"effectiveValue": {
object (ExtendedValue)
},
"formattedValue": string,
"userEnteredFormat": {
object (CellFormat)
},
"effectiveFormat": {
object (CellFormat)
},
"hyperlink": string,
"note": string,
"textFormatRuns": [
{
object (TextFormatRun)
}
],
"dataValidation": {
object (DataValidationRule)
},
"pivotTable": {
object (PivotTable)
}
}
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=CellData", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellData", "protocol=uri"

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
52 changes: 47 additions & 5 deletions sheets/src/objects/eg_color.e
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ note
class
EG_COLOR

inherit

ANY
redefine
default_create
end

create
default_create

feature {NONE} -- Initialization

default_create
do
is_default := True
end

feature -- Access

Expand All @@ -37,47 +53,73 @@ feature -- Access
-- 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.
-- 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).

is_default: BOOLEAN
-- Are the attributes in default values?


feature -- Element Change

set_red (a_val: REAL)
-- Set `red` to `a_val`.
do
is_default := False
red := a_val
ensure
not_default: not is_default
red_set: red = a_val
end

set_green (a_val: REAL)
do
is_default := False
green := a_val
ensure
not_default: not is_default
green_set: green = a_val
end

set_blue (a_val: REAL)
do
is_default := False
blue := a_val
ensure
not_default: not is_default
blue_set: blue = a_val
end

set_alpha (a_val: REAL)
do
is_default := False
alpha := a_val
ensure
not_default: not is_default
alpha_set: alpha = a_val
end

reset
-- Reset the attributes to default values.
do
is_default := True
red := 0
green := 0
blue := 0
alpha := 0
end

feature -- Eiffel to JSON

to_json: JSON_OBJECT
-- Json representation of current object.
do
create Result.make_with_capacity (4)
Result.put (create {JSON_NUMBER}.make_real (red), "red")
Result.put (create {JSON_NUMBER}.make_real (green), "green")
Result.put (create {JSON_NUMBER}.make_real (blue), "blue")
Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha")
if is_default then
create Result.make
else
create Result.make_with_capacity (4)
Result.put (create {JSON_NUMBER}.make_real (red), "red")
Result.put (create {JSON_NUMBER}.make_real (green), "green")
Result.put (create {JSON_NUMBER}.make_real (blue), "blue")
Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha")
end
end

invariant
Expand Down
Loading

0 comments on commit 1c82a5f

Please sign in to comment.