class Workbook::Column
Column
helps us to store general properties of a column, and lets us easily perform operations on values within a column
Attributes
limit[RW]
width[RW]
Public Class Methods
alpha_index_to_number_index(string)
click to toggle source
Helps to convert from e.g. “AA” to 26 @param [String] string that typically identifies a column @return [Integer]
# File lib/workbook/column.rb, line 88 def alpha_index_to_number_index string sum = 0 string.upcase.chars.each_with_index do | char, char_index| sum = sum * 26 + char.unpack('U')[0]-64 end return sum-1 end
new(table=nil, options={})
click to toggle source
# File lib/workbook/column.rb, line 11 def initialize(table=nil, options={}) self.table = table options.each{ |k,v| self.public_send("#{k}=",v) } end
Public Instance Methods
column_type()
click to toggle source
Returns column type, either :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :date, :binary, :boolean
# File lib/workbook/column.rb, line 17 def column_type return @column_type if defined?(@column_type) ind = self.index table[1..500].each do |row| if row[ind] and row[ind].cell_type cel_column_type = row[ind].cell_type if !defined?(@column_type) or @column_type.nil? @column_type = cel_column_type elsif cel_column_type == @column_type or cel_column_type == :nil else @column_type = :string break end end end return @column_type end
column_type=(column_type)
click to toggle source
# File lib/workbook/column.rb, line 53 def column_type= column_type if [:primary_key, :string, :text, :integer, :float, :decimal, :datetime, :date, :binary, :boolean].include? column_type @column_type = column_type else raise ArgumentError, "value should be a symbol indicating a primitive type, e.g. a string, or an integer (valid values are: :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :date, :binary, :boolean)" end end
default()
click to toggle source
default cell
# File lib/workbook/column.rb, line 75 def default return @default end
default=(value)
click to toggle source
# File lib/workbook/column.rb, line 79 def default= value @default = value if value.class == Cell @default = Cell.new(value) end
head_value()
click to toggle source
# File lib/workbook/column.rb, line 62 def head_value begin table.header[index].value rescue return "!noheader!" end end
index()
click to toggle source
Returns index of the column within the table's columns-set @return [Integer, NilClass]
# File lib/workbook/column.rb, line 37 def index table.columns.index self end
inspect()
click to toggle source
# File lib/workbook/column.rb, line 70 def inspect "<Workbook::Column index=#{index}, header=#{head_value}>" end
table()
click to toggle source
@return [Workbook::Table]
# File lib/workbook/column.rb, line 49 def table @table end
table=(table)
click to toggle source
Set the table this column belongs to @param [Workbook::Table] table this column belongs to
# File lib/workbook/column.rb, line 43 def table= table raise(ArgumentError, "value should be nil or Workbook::Table") unless [NilClass,Workbook::Table].include? table.class @table = table end