lib/axlsx.rb in axlsx-1.2.3 vs lib/axlsx.rb in axlsx-1.3.1
- old
+ new
@@ -35,11 +35,16 @@
Object.send :define_method, :instance_values do
Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
end
end
-# xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
+# xlsx generation with charts, images, automated column width, customizable styles
+# and full schema validation. Axlsx excels at helping you generate beautiful
+# Office Open XML Spreadsheet documents without having to understand the entire
+# ECMA specification. Check out the README for some examples of how easy it is.
+# Best of all, you can validate your xlsx file before serialization so you know
+# for sure that anything generated is going to load on your client's machine.
module Axlsx
# determines the cell range for the items provided
def self.cell_range(cells, absolute=true)
return "" unless cells.first.is_a? Cell
@@ -63,10 +68,11 @@
end
# returns the x, y position of a cell
def self.name_to_indices(name)
raise ArgumentError, 'invalid cell name' unless name.size > 1
+ # capitalization?!?
v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val
end
[v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1]
end
@@ -93,9 +99,10 @@
# performs the increadible feat of changing snake_case to CamelCase
# @param [String] s The snake case string to camelize
# @return [String]
def self.camel(s="", all_caps = true)
+ s = s.to_s
s = s.capitalize if all_caps
s.gsub(/_(.)/){ $1.upcase }
end
end