Skip to content

Commit

Permalink
Extract Roo::Font to replace equivalent uses in Excelx and OpenOffice.
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed Nov 24, 2014
1 parent d466950 commit 23e19de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
17 changes: 1 addition & 16 deletions lib/roo/excelx/styles.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
require 'roo/font'
require 'roo/excelx/extractor'

module Roo
class Excelx::Styles < Excelx::Extractor
class Font
attr_accessor :bold, :italic, :underline

def bold?
@bold == true
end

def italic?
@italic == true
end

def underline?
@underline == true
end
end

# convert internal excelx attribute to a format
def style_format(style)
id = num_fmt_ids[style.to_i]
Expand Down
17 changes: 17 additions & 0 deletions lib/roo/font.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Roo
class Font
attr_accessor :bold, :italic, :underline

def bold?
@bold
end

def italic?
@italic
end

def underline?
@underline
end
end
end
19 changes: 2 additions & 17 deletions lib/roo/open_office.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'nokogiri'
require 'cgi'
require 'zip/filesystem'
require 'roo/font'

class Roo::OpenOffice < Roo::Base
# initialization and opening of a spreadsheet file
Expand Down Expand Up @@ -82,22 +83,6 @@ def formulas(sheet=nil)
end
end

class Font
attr_accessor :bold, :italic, :underline

def bold?
@bold == 'bold'
end

def italic?
@italic == 'italic'
end

def underline?
@underline != nil
end
end

# Given a cell, return the cell's style
def font(row, col, sheet=nil)
sheet ||= default_sheet
Expand Down Expand Up @@ -391,7 +376,7 @@ def read_labels
end

def read_styles(style_elements)
@style_definitions['Default'] = Roo::OpenOffice::Font.new
@style_definitions['Default'] = Roo::Font.new
style_elements.each do |style|
next unless style.name == 'style'
style_name = attr(style,'name')
Expand Down

0 comments on commit 23e19de

Please sign in to comment.