<commit_before>Utils = require('./utils')
StyleMixin = require('./style_mixin')
Calculator = require('./formula')

class Cell
  StyleMixin.mixin(@prototype)

  constructor:(row, colIndex, xmlobj)->
    @_ = {}
    @_.row = row
    @_.rowIndex = @row.rowIndex
    @_.colIndex = colIndex
    @_.type = xmlobj?.$.t
    @_.value = xmlobj?.v?[0]
    @_.formula = xmlobj?.f?[0]

    styleId = (parseInt xmlobj?.$.s) || 0
    StyleMixin.bind(this, styleId)

    if @_.value?._
      @_.value = @_.value._

    if @_.value instanceof Object
      if @_.value._
        @_.value = @_.value._
      else if @_.value.$['xml:space']
        @_.value = ""


    if @_.formula?.$
      attr = @_.formula.$
      @_.formula = @_.formula._
      if attr.t == "shared"
        if @_.formula
          @worksheet._.sft = {} unless @worksheet._.sft
          @worksheet._.sft[attr.si] = [@_.formula, @rowIndex, @colIndex]
        else
          [formula, rowIdx, colIdx] = @worksheet._.sft[attr.si]
          @_.formula = formula.replace /(".*?")|(\$?)([A-Z]+)(\$?)(\d+)/g, (m0, m1, m2, m3, m4, m5)=>
            return m1 if m1
            c = Utils.toDigit(m3)
            r = parseInt m5
            rr = @rowIndex
            cc = @colIndex
            unless m2
              c -= colIdx - cc
            unless m4
              r -= rowIdx - rr
            return Utils.toAddr(r, c, !!m4, !!m2)

  Object.defineProperties @prototype,
    "workbook":
      get: -> @row.workbook
    "worksheet":
      get: -> @row.worksheet
    "row":
      get: -> @_.row
    "column":
      get: ->
        @_.col = @_.col || @worksheet.getColumn(@_.colIndex)
    "value":
      get: ->
        val = @_.value
        switch @_.type
          when "s"
            val = @workbook._.sst.get(@_.value)
        if @_.styleMixin.style.numberFormat.isDate()
          val = Utils.offsetToDate(val)
        val

      set: (val) ->
        if typeof val ==  "number"
          @_.type = null
        else if val instanceof Date
          @_.type = null
          val = Utisl.dateToOffset(val)
        else
          val = @workbook._.sst.add(val)
          @_.type = "s"

        @_.value = val

    "formula":
      get: -> @_.formula
      set: (val) ->
        @_.formula = val
        @_.type = null

    "rowIndex":
      get: -> @_.rowIndex

    "colIndex":
      get: -> @_.colIndex

    "addr":
      get: -> Utils.toAddr(@_.rowIndex, @_.colIndex)

    "style":
      get: ->
        s = @_.style.clone()
        @_.style = s
        s

  calculate: ->
    Calculator(@worksheet, @formula)

  toXmlObj: ->

    obj = {
      $:{
        r:@addr
      }
    }

    if @_.formula
      obj.f = [@_.formula]

    value = @_.value
    if value
      value = value + ""
      if value == value.trim()
        obj.v = [value]
      else
        obj.v = [{$:{"xml:space":"preserve"}, _:value}]

    obj.$.s = @_.styleMixin.style.id

    if @_.type
      obj.$.t = @_.type

    obj

module.exports = Cell
<commit_msg>Change to do explicit casting<commit_after>Utils = require('./utils')
StyleMixin = require('./style_mixin')
Calculator = require('./formula')

class Cell
  StyleMixin.mixin(@prototype)

  constructor:(row, colIndex, xmlobj)->
    @_ = {}
    @_.row = row
    @_.rowIndex = @row.rowIndex
    @_.colIndex = colIndex
    @_.type = xmlobj?.$.t
    @_.value = xmlobj?.v?[0]
    @_.formula = xmlobj?.f?[0]

    styleId = (parseInt xmlobj?.$.s) || 0
    StyleMixin.bind(this, styleId)

    if @_.value?._
      @_.value = @_.value._

    if @_.value instanceof Object
      if @_.value._
        @_.value = @_.value._
      else if @_.value.$['xml:space']
        @_.value = ""


    if @_.formula?.$
      attr = @_.formula.$
      @_.formula = @_.formula._
      if attr.t == "shared"
        if @_.formula
          @worksheet._.sft = {} unless @worksheet._.sft
          @worksheet._.sft[attr.si] = [@_.formula, @rowIndex, @colIndex]
        else
          [formula, rowIdx, colIdx] = @worksheet._.sft[attr.si]
          @_.formula = formula.replace /(".*?")|(\$?)([A-Z]+)(\$?)(\d+)/g, (m0, m1, m2, m3, m4, m5)=>
            return m1 if m1
            c = Utils.toDigit(m3)
            r = parseInt m5
            rr = @rowIndex
            cc = @colIndex
            unless m2
              c -= colIdx - cc
            unless m4
              r -= rowIdx - rr
            return Utils.toAddr(r, c, !!m4, !!m2)

  Object.defineProperties @prototype,
    "workbook":
      get: -> @row.workbook
    "worksheet":
      get: -> @row.worksheet
    "row":
      get: -> @_.row
    "column":
      get: ->
        @_.col = @_.col || @worksheet.getColumn(@_.colIndex)
    "value":
      get: ->
        val = @_.value
        switch @_.type
          when "s"
            val = @workbook._.sst.get(@_.value)
          when "str"
            val = String(val)
          else
            if Utils.isNumber(val)
              val = Number(val)
        if @_.styleMixin.style.numberFormat.isDate()
          val = Utils.offsetToDate(val)
        val

      set: (val) ->
        if typeof val ==  "number"
          @_.type = null
        else if val instanceof Date
          @_.type = null
          val = Utisl.dateToOffset(val)
        else
          val = @workbook._.sst.add(val)
          @_.type = "s"

        @_.value = val

    "formula":
      get: -> @_.formula
      set: (val) ->
        @_.formula = val
        @_.type = null

    "rowIndex":
      get: -> @_.rowIndex

    "colIndex":
      get: -> @_.colIndex

    "addr":
      get: -> Utils.toAddr(@_.rowIndex, @_.colIndex)

    "style":
      get: ->
        s = @_.style.clone()
        @_.style = s
        s

  calculate: ->
    Calculator(@worksheet, @formula)

  toXmlObj: ->

    obj = {
      $:{
        r:@addr
      }
    }

    if @_.formula
      obj.f = [@_.formula]

    value = @_.value
    if value
      value = value + ""
      if value == value.trim()
        obj.v = [value]
      else
        obj.v = [{$:{"xml:space":"preserve"}, _:value}]

    obj.$.s = @_.styleMixin.style.id

    if @_.type
      obj.$.t = @_.type

    obj

module.exports = Cell

{'fraction_non_alphanumeric': 0.1669664758789861, 'fraction_numerical': 0.005560098119378578, 'mean_word_length': 1.5451518934665003, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4069580', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2080, 'n_words': 455}