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.



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

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.



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

def annotation
  @annotation
end

#bookObject

Returns the value of attribute book.



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

def book
  @book
end

#codeObject

Returns the value of attribute code.



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

def code
  @code
end

#encodingObject

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#kindObject

Returns the value of attribute kind.



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

def kind
  @kind
end

#numericObject

Returns the value of attribute numeric.



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

def numeric
  @numeric
end

#richObject

Returns the value of attribute rich.



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

def rich
  @rich
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#dateObject



31
32
33
# File 'lib/parseexcel/parseexcel.rb', line 31

def date
  @row.date @idx
end

#datetimeObject



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

def datetime
  @row.datetime @idx
end

#to_fObject



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

def to_f
  @value.to_f
end

#to_iObject



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

def to_i
  @value.to_i
end

#to_s(target_encoding = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/parseexcel/parseexcel.rb', line 43

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



54
55
56
57
58
59
60
61
62
# File 'lib/parseexcel/parseexcel.rb', line 54

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