class SpreadsheetAccessor

Constants

VERSION

Attributes

cells[RW]
sheet[RW]

Public Class Methods

cell( name ) click to toggle source
# File lib/spreadsheet_accessor.rb, line 10
def self.cell( name )
        row = 0
        col = 0
        
        name.upcase!
        if /^([A-Z]+)/ =~ name
                bytes = $1.bytes
                col = bytes.pop - @@col_start_index
                bytes.reverse.each_with_index{|byte, i|
                        value = byte - @@col_start_index + 1
                        ( i + 1 ).times{
                                value *= @@alphabet_size
                        }
                        col += value
                }
        end
        
        row = $1.to_i - 1 if /([0-9]+)$/ =~ name
        
        {
                :name        => name,
                :row => row,
                :col => col
        }
end
index( data ) click to toggle source
# File lib/spreadsheet_accessor.rb, line 36
def self.index( data )
        row = 0
        col = 0
        
        if data.instance_of?( String )
                hash = SpreadsheetAccessor.cell( data )
                row = hash[ :row ]
                col = hash[ :col ]
        elsif data.instance_of?( Array )
                row = data[ 0 ]
                col = data[ 1 ]
        elsif data.instance_of?( Hash )
                row = data[ :row ] if data.key?( :row )
                col = data[ :col ] if data.key?( :col )
        end
        
        {
                :row => row,
                :col => col
        }
end
new( sheet = nil ) click to toggle source
# File lib/spreadsheet_accessor.rb, line 58
def initialize( sheet = nil )
        self.sheet = sheet
end

Public Instance Methods

cell( data ) click to toggle source
# File lib/spreadsheet_accessor.rb, line 67
def cell( data )
        hash = SpreadsheetAccessor.index( data )
        cell = @cells[ hash[ :row ], hash[ :col ] ]
        cell.instance_of?( Spreadsheet::Formula ) ? cell.value : cell
end
sheet=( sheet ) click to toggle source
# File lib/spreadsheet_accessor.rb, line 62
def sheet=( sheet )
        @sheet = sheet
        @cells = sheet
end