com.colisweb.gdrive.client.sheets.GoogleGridRange.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of google-drive-scala-client_2.13 Show documentation
Show all versions of google-drive-scala-client_2.13 Show documentation
Google Drive Scala Client is a Scala wrapper around the Google Drive client for Java
The newest version!
package com.colisweb.gdrive.client.sheets
import com.google.api.services.sheets.v4.model.GridRange
final case class GoogleGridRange(
sheetId: Int,
row: Option[GoogleDimensionRange] = None,
column: Option[GoogleDimensionRange] = None
) {
val toGoogle: GridRange = {
val gridRange = new GridRange().setSheetId(sheetId)
val rowGridRange = row.fold(gridRange) {
case GoogleDimensionRange(i, None) => gridRange.setStartRowIndex(i)
case GoogleDimensionRange(i, Some(length)) => gridRange.setStartRowIndex(i).setEndRowIndex(i + length)
}
column.fold(rowGridRange) {
case GoogleDimensionRange(i, None) => rowGridRange.setStartRowIndex(i)
case GoogleDimensionRange(i, Some(length)) => rowGridRange.setStartColumnIndex(i).setEndColumnIndex(i + length)
}
}
}
object GoogleGridRange {
def singleRow(sheetId: Int, rowIndex: Int): GoogleGridRange =
multipleRows(sheetId, rowIndex, 1)
def singleColumn(sheetId: Int, columnIndex: Int): GoogleGridRange =
multipleColumns(sheetId, columnIndex, 1)
def multipleRows(sheetId: Int, rowIndex: Int, length: Int): GoogleGridRange =
GoogleGridRange(sheetId, row = Some(GoogleDimensionRange(rowIndex, Some(length))))
def multipleColumns(sheetId: Int, rowIndex: Int, length: Int): GoogleGridRange =
GoogleGridRange(sheetId, column = Some(GoogleDimensionRange(rowIndex, Some(length))))
}