Module: SpreadsheetArchitect::Utils::ODS

Defined in:
lib/spreadsheet_architect/utils/ods.rb

Class Method Summary collapse

Class Method Details

.convert_styles(styles = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spreadsheet_architect/utils/ods.rb', line 28

def self.convert_styles(styles={})
  styles = {} unless styles.is_a?(Hash)
  styles = SpreadsheetArchitect::Utils.stringify_keys(styles)

  property_styles = {}

  text_styles = {}
  text_styles['font-weight'] = styles.delete('bold') ? 'bold' : styles.delete('font-weight')
  text_styles['font-size'] = styles.delete('font_size') || styles.delete('font-size')
  text_styles['font-style'] = styles.delete('italic') ? 'italic' : styles.delete('font-style')
  if styles['underline']
    styles.delete('underline')
    text_styles['text-underline-style'] = 'solid'
    text_styles['text-underline-type'] = 'single'
  end
  if styles['align']
    text_styles['align'] = true
  end 
  if styles['color'].respond_to?(:sub) && !styles['color'].empty?
    text_styles['color'] = "##{styles.delete('color').sub('#','')}"
  end
  text_styles.delete_if{|_,v| v.nil?}
  property_styles['text'] = text_styles
  
  cell_styles = {}
  styles['background_color'] ||= styles.delete('background-color')
  if styles['background_color'].respond_to?(:sub) && !styles['background_color'].empty?
    cell_styles['background-color'] = "##{styles.delete('background_color').sub('#','')}"
  end

  cell_styles.delete_if{|_,v| v.nil?}
  property_styles['cell'] = cell_styles

  return property_styles
end

.get_cell_type(value, type = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spreadsheet_architect/utils/ods.rb', line 5

def self.get_cell_type(value, type=nil)
  if type && !type.empty?
    case type
    when :hyperlink
      return :string
    when :date, :time
      return :string
    end

    return type unless (type.respond_to?(:empty?) ? type.empty? : type.nil?)
  end
  
  if value.is_a?(Numeric)
    type = :float
  elsif value.respond_to?(:strftime)
    type = :string
  else
    type = :string
  end

  return type
end