Class: Workbook::Format
- Inherits:
-
Hash
- Object
- Hash
- Workbook::Format
- Includes:
- Modules::RawObjectsStorage
- Defined in:
- lib/workbook/format.rb
Overview
Format is an object used for maintinaing a cell’s formatting. It can belong to many cells. It maintains a relation to the raw template’s equivalent, to preserve attributes Workbook cannot modify/access.
Instance Attribute Summary (collapse)
-
- (Object) name
Returns the value of attribute name.
Instance Method Summary (collapse)
-
- (Boolean) has_background_color?(color = :any)
Does the current format feature a background color? (not black or white or transparant).
-
- (Format) initialize(options = {})
constructor
Initialize.
-
- (Object) merge(other_format)
Combines the formatting options of one with another, removes as a consequence the reference to the raw object’s equivalent.
- - (Object) merge_hash
-
- (String) to_css
Returns a string that can be used as inline cell styling (e.g. `<td style=“<%=cell.format.to_css%>”><%=cell%></td>`).
Methods included from Modules::RawObjectsStorage
#add_raw, #has_raw_for?, #raws, #remove_all_raws!, #return_raw_for
Constructor Details
- (Format) initialize(options = {})
Initialize
13 |
# File 'lib/workbook/format.rb', line 13 def initialize ={} |
Instance Attribute Details
- (Object) name
Returns the value of attribute name
9 10 11 |
# File 'lib/workbook/format.rb', line 9 def name @name end |
Instance Method Details
- (Boolean) has_background_color?(color = :any)
Does the current format feature a background color? (not black or white or transparant).
18 19 20 21 22 23 24 |
# File 'lib/workbook/format.rb', line 18 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(other_format)
Combines the formatting options of one with another, removes as a consequence the reference to the raw object’s equivalent.
37 38 39 40 |
# File 'lib/workbook/format.rb', line 37 def merge(other_format) self.remove_all_raws! self.merge_hash(other_format) end |
- (Object) merge_hash
7 |
# File 'lib/workbook/format.rb', line 7 alias_method :merge_hash, :merge |
- (String) to_css
Returns a string that can be used as inline cell styling (e.g. `<td style=“<%=cell.format.to_css%>”><%=cell%></td>`)
28 29 30 31 32 33 |
# File 'lib/workbook/format.rb', line 28 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 |