Class: Workbook::Format

Inherits:
Hash
  • Object
show all
Includes:
Modules::RawObjectsStorage
Defined in:
lib/workbook/format.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Modules::RawObjectsStorage

#add_raw, #has_raw_for?, #raws, #remove_all_raws!, #return_raw_for

Constructor Details

- (Format) initialize(options = {})



10
11
12
# File 'lib/workbook/format.rb', line 10

def initialize options={}
  options.each {|k,v| self[k]=v}
end

Instance Attribute Details

- (Object) name

Returns the value of attribute name



8
9
10
# File 'lib/workbook/format.rb', line 8

def name
  @name
end

Instance Method Details

- (Boolean) has_background_color?(color = :any)



14
15
16
17
18
19
20
# File 'lib/workbook/format.rb', line 14

def has_background_color? color=:any
  if self[:background_color]
    return (self[:background_color].downcase==color.to_s.downcase or (!(self[:background_color]==nil or (self[:background_color].is_a? String and (self[:background_color].downcase=='#ffffff' or self[:background_color]=='#000000'))) and color==:any))
  else
    return false
  end
end

- (Object) merge(a)



30
31
32
33
# File 'lib/workbook/format.rb', line 30

def merge(a)
  self.remove_all_raws!
  self.merge_hash(a)
end

- (Object) merge_hash



6
# File 'lib/workbook/format.rb', line 6

alias_method :merge_hash, :merge

- (Object) to_css

Returns a string that can be used as inline cell styling (e.g. `<td style="<%=cell.format.to_css%>"><%=cell%></td>`)



23
24
25
26
27
28
# File 'lib/workbook/format.rb', line 23

def to_css
  css_parts = []
  css_parts.push("background: #{self[:background_color].to_s} #{self[:background].to_s}".strip) if self[:background] or self[:background_color]
  css_parts.push("color: #{self[:color].to_s}") if self[:color]
  css_parts.join("; ")
end