lib/cell.rb in rxl-0.4.0 vs lib/cell.rb in rxl-0.4.1

- old
+ new

@@ -6,45 +6,44 @@ ### GET HASH CELL FROM RUBYXL CELL ### ############################################## def self.rubyxl_cell_to_hash_cell(rubyxl_cell = nil) rubyxl_cell_value = rubyxl_cell.nil? ? RubyXL::Cell.new.value : rubyxl_cell.value - values = { + { value: rubyxl_cell_value, format: hash_cell_format(rubyxl_cell_value), formula: rubyxl_cell_formula(rubyxl_cell), - h_align: rubyxl_cell_horizontal_alignment(rubyxl_cell), - v_align: rubyxl_cell_vertical_alignment(rubyxl_cell), - bold: rubyxl_cell.is_bolded, - fill: rubyxl_cell.fill_color, - font_name: rubyxl_cell.font_name, - font_size: rubyxl_cell.font_size.to_i, + h_align: rubyxl_cell_h_align(rubyxl_cell), + v_align: rubyxl_cell_v_align(rubyxl_cell), + bold: rubyxl_cell.nil? ? false : rubyxl_cell.is_bolded, + fill: rubyxl_cell.nil? ? 'ffffff' : rubyxl_cell.fill_color, + font_name: rubyxl_cell.nil? ? 'Calibri' : rubyxl_cell.font_name, + font_size: rubyxl_cell.nil? ? 12 : rubyxl_cell.font_size.to_i, border: rubyxl_cell_to_border_hash(rubyxl_cell) } - return values end def self.rubyxl_cell_to_border_hash(rubyxl_cell) { - top: rubyxl_cell.get_border(:top), - bottom: rubyxl_cell.get_border(:bottom), - left: rubyxl_cell.get_border(:left), - right: rubyxl_cell.get_border(:right) + top: rubyxl_cell.nil? ? nil : rubyxl_cell.get_border(:top), + bottom: rubyxl_cell.nil? ? nil : rubyxl_cell.get_border(:bottom), + left: rubyxl_cell.nil? ? nil : rubyxl_cell.get_border(:left), + right: rubyxl_cell.nil? ? nil : rubyxl_cell.get_border(:right) } end def self.rubyxl_cell_formula(rubyxl_cell) return nil if rubyxl_cell.nil? || rubyxl_cell.formula.nil? || rubyxl_cell.formula.expression.empty? rubyxl_cell.formula.expression end - def self.rubyxl_cell_horizontal_alignment(rubyxl_cell) - return nil if rubyxl_cell.nil? || rubyxl_cell.horizontal_alignment.nil? + def self.rubyxl_cell_h_align(rubyxl_cell) + return :left if rubyxl_cell.nil? || rubyxl_cell.horizontal_alignment.nil? rubyxl_cell.horizontal_alignment.to_sym end - def self.rubyxl_cell_vertical_alignment(rubyxl_cell) + def self.rubyxl_cell_v_align(rubyxl_cell) return :bottom if rubyxl_cell.nil? || rubyxl_cell.vertical_alignment.nil? rubyxl_cell.vertical_alignment.to_sym end def self.hash_cell_format(rubyxl_cell_value) @@ -106,11 +105,10 @@ unless hash_cell.keys.reject { |key| key.is_a?(Symbol) }.empty? raise("cell key at path #{trace + [hash_cell_key]} must be a Symbol") end invalid_keys = hash_cell.keys.delete_if { |key| valid_cell_keys.include?(key) } unless invalid_keys.empty? - valid_cell_keys_string = ":#{valid_cell_keys.join(', :')}" - raise(%(invalid cell hash key(s) #{invalid_keys} at path #{trace + [hash_cell_key]}, valid keys are: [#{valid_cell_keys_string}])) + raise(%(invalid cell hash key(s) #{invalid_keys} at path #{trace + [hash_cell_key]})) end # TODO: add validation for hash_cell specification end def self.validate_cell_key(cell_key) \ No newline at end of file