Class: TableSetting::Style
- Inherits:
-
Object
- Object
- TableSetting::Style
- Defined in:
- lib/table_setting/style.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#bold ⇒ Object
readonly
Returns the value of attribute bold.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #bold? ⇒ Boolean
-
#initialize(cell, options = {}) ⇒ Style
constructor
A new instance of Style.
- #name ⇒ Object
- #to_css ⇒ Object
- #to_xls_xml ⇒ Object
- #update(options) ⇒ Object
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, = {}) @bold = [:bold] || cell.row.bold? @size = [:size] || cell.row.size @background = [:background] || cell.row.background @color = [:color] || cell.row.color end |
Instance Attribute Details
#background ⇒ Object (readonly)
Returns the value of attribute background.
2 3 4 |
# File 'lib/table_setting/style.rb', line 2 def background @background end |
#bold ⇒ Object (readonly)
Returns the value of attribute bold.
2 3 4 |
# File 'lib/table_setting/style.rb', line 2 def bold @bold end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
2 3 4 |
# File 'lib/table_setting/style.rb', line 2 def color @color end |
#size ⇒ Object (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
27 28 29 |
# File 'lib/table_setting/style.rb', line 27 def bold? bold end |
#name ⇒ Object
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_css ⇒ Object
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_xml ⇒ Object
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() @bold = [:bold] if [:bold] @background = [:background] if [:background] @color = [:color] if [:color] @size = [:size] if [:size] end |