Class: TableSetting::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/table_setting/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cell, options = {}) ⇒ Style

Returns a new instance of Style.



3
4
5
6
7
8
# File 'lib/table_setting/style.rb', line 3

def initialize(cell, options = {})
  @bold =       options[:bold]       || cell.row.bold?
  @size =       options[:size]       || cell.row.size
  @background = options[:background] || cell.row.background
  @color =      options[:color]      || cell.row.color
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



2
3
4
# File 'lib/table_setting/style.rb', line 2

def background
  @background
end

#boldObject (readonly)

Returns the value of attribute bold.



2
3
4
# File 'lib/table_setting/style.rb', line 2

def bold
  @bold
end

#colorObject (readonly)

Returns the value of attribute color.



2
3
4
# File 'lib/table_setting/style.rb', line 2

def color
  @color
end

#sizeObject (readonly)

Returns the value of attribute size.



2
3
4
# File 'lib/table_setting/style.rb', line 2

def size
  @size
end

Instance Method Details

#bold?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/table_setting/style.rb', line 27

def bold?
  bold
end

#nameObject



17
18
19
20
21
22
23
24
25
# File 'lib/table_setting/style.rb', line 17

def name
  settings = {
    bold:       bold?,
    background: background,
    size:       size,
    color:      color
  }
  "style-#{Digest::MD5.hexdigest(settings.to_s)[0..7]}"
end

#to_cssObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/table_setting/style.rb', line 31

def to_css
  signature = ''
  if bold?
    signature += "font-weight: bold;"
  end
  if size
    signature += "font-size: #{size};"
  end
  if background
    signature += "background-color: #{background};"
  end
  if color
    signature += "color: #{color};"
  end
  signature
end

#to_xls_xmlObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/table_setting/style.rb', line 48

def to_xls_xml
  signature = ''
  font_specs = {}
  if bold?
    font_specs["ss:Bold"] = 1
  end
  if size
  end
  if background
    signature += %Q{<Interior ss:Color="#{background}" ss:Pattern="Solid"/>}
  end
  if color
    font_specs["ss:Color"] = color
  end
  unless font_specs.empty?
    spec_string = ''
    font_specs.each do |key, value|
      spec_string += %Q{#{key}="#{value}" }
    end
    signature += "<ss:Font #{spec_string} />"
  end

  signature
end

#update(options) ⇒ Object



10
11
12
13
14
15
# File 'lib/table_setting/style.rb', line 10

def update(options)
  @bold       = options[:bold]       if options[:bold]
  @background = options[:background] if options[:background]
  @color      = options[:color]      if options[:color]
  @size       = options[:size]       if options[:size]
end