Class: OOXML::Excel::Sheet::Row::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_excel/sheet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ Cell

Returns a new instance of Cell.



190
191
192
# File 'lib/ooxml_excel/sheet.rb', line 190

def initialize(**attrs)
  attrs.each { |property, value| send("#{property}=", value)}
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



188
189
190
# File 'lib/ooxml_excel/sheet.rb', line 188

def id
  @id
end

#shared_stringsObject

Returns the value of attribute shared_strings.



188
189
190
# File 'lib/ooxml_excel/sheet.rb', line 188

def shared_strings
  @shared_strings
end

#style_idObject

Returns the value of attribute style_id.



188
189
190
# File 'lib/ooxml_excel/sheet.rb', line 188

def style_id
  @style_id
end

#stylesObject

Returns the value of attribute styles.



188
189
190
# File 'lib/ooxml_excel/sheet.rb', line 188

def styles
  @styles
end

#type_idObject

Returns the value of attribute type_id.



188
189
190
# File 'lib/ooxml_excel/sheet.rb', line 188

def type_id
  @type_id
end

#value_idObject

Returns the value of attribute value_id.



188
189
190
# File 'lib/ooxml_excel/sheet.rb', line 188

def value_id
  @value_id
end

Class Method Details

.load_from_node(cell_node, shared_strings, styles) ⇒ Object



242
243
244
245
246
247
248
249
# File 'lib/ooxml_excel/sheet.rb', line 242

def self.load_from_node(cell_node, shared_strings, styles)
  new(id: cell_node.attributes["r"].try(:value),
      type_id: cell_node.attributes["t"].try(:value),
      style_id: cell_node.attributes["s"].try(:value),
      value_id: cell_node.at('v').try(:text),
      shared_strings: shared_strings,
      styles: styles )
end

Instance Method Details

#fillObject



228
229
230
# File 'lib/ooxml_excel/sheet.rb', line 228

def fill
  (style.present?) ? style[:fill]: nil
end

#fontObject



224
225
226
# File 'lib/ooxml_excel/sheet.rb', line 224

def font
  (style.present?) ? style[:font] : nil
end

#number_formatObject



217
218
219
220
221
222
# File 'lib/ooxml_excel/sheet.rb', line 217

def number_format
  if (style.present?)
    nf = style[:number_format]
    (nf.present?) ? nf.gsub("\\", "") : nil
  end
end

#styleObject



209
210
211
212
213
214
215
# File 'lib/ooxml_excel/sheet.rb', line 209

def style
  @style ||= begin
    if s.present?
      style = styles.by_id(s.to_i)
    end
  end
end

#typeObject



194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/ooxml_excel/sheet.rb', line 194

def type
  @type ||= begin
    case type_id
    when 's' then :string
    when 'n' then :number
    when 'b' then :boolean
    when 'd' then :date
    when 'str' then :formula
    when 'inlineStr' then :inline_str
    else
      :error
    end
  end
end

#valueObject



232
233
234
235
236
237
238
239
240
# File 'lib/ooxml_excel/sheet.rb', line 232

def value
  case type
  when :string
    (value_id.present?) ? shared_strings[value_id.to_i] : nil
  else
    # TODO: to support other types soon
    value_id
  end
end