Class: Spreadsheet::ParseExcel::Worksheet::Cell

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, format, row, idx) ⇒ Cell

Returns a new instance of Cell.



25
26
27
28
29
30
31
# File 'lib/parseexcel/parseexcel.rb', line 25

def initialize value, format, row, idx
  @format = format
  @idx = idx
  @row = row
  @value = value
  @encoding = Spreadsheet.client_encoding
end

Instance Attribute Details

#annotationObject

Returns the value of attribute annotation.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def annotation
  @annotation
end

#bookObject

Returns the value of attribute book.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def book
  @book
end

#codeObject

Returns the value of attribute code.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def code
  @code
end

#encodingObject

Returns the value of attribute encoding.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def encoding
  @encoding
end

#formatObject

Returns the value of attribute format.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def format
  @format
end

#kindObject

Returns the value of attribute kind.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def kind
  @kind
end

#numericObject

Returns the value of attribute numeric.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def numeric
  @numeric
end

#richObject

Returns the value of attribute rich.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def rich
  @rich
end

#valueObject

Returns the value of attribute value.



23
24
25
# File 'lib/parseexcel/parseexcel.rb', line 23

def value
  @value
end

Instance Method Details

#dateObject



33
34
35
# File 'lib/parseexcel/parseexcel.rb', line 33

def date
  @row.date @idx
end

#datetimeObject



37
38
39
# File 'lib/parseexcel/parseexcel.rb', line 37

def datetime
  @row.datetime @idx
end

#to_fObject



45
46
47
# File 'lib/parseexcel/parseexcel.rb', line 45

def to_f
  @value.to_f
end

#to_iObject



41
42
43
# File 'lib/parseexcel/parseexcel.rb', line 41

def to_i
  @value.to_i
end

#to_s(target_encoding = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/parseexcel/parseexcel.rb', line 49

def to_s(target_encoding = nil)
  if target_encoding
    begin
      Iconv.new(target_encoding, @encoding).iconv(@value)
    rescue
      Iconv.new(target_encoding, "ascii").iconv(@value.to_s)
    end
  else
    @value.to_s
  end
end

#typeObject



61
62
63
64
65
66
67
68
69
# File 'lib/parseexcel/parseexcel.rb', line 61

def type
  if @format && (@format.date? || @format.time?)
    :date
  elsif @value.is_a?(Numeric)
    :numeric
  else
    :text
  end
end