Class: Creeker::Book
- Inherits:
-
Object
- Object
- Creeker::Book
- Defined in:
- lib/creeker/book.rb
Constant Summary collapse
- DATE_1900 =
Date.new(1899, 12, 30).freeze
- DATE_1904 =
Date.new(1904, 1, 1).freeze
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#shared_strings ⇒ Object
readonly
Returns the value of attribute shared_strings.
-
#sheets ⇒ Object
readonly
Returns the value of attribute sheets.
Instance Method Summary collapse
- #base_date ⇒ Object
- #close ⇒ Object
-
#initialize(path, options = {}) ⇒ Book
constructor
A new instance of Book.
- #style_types ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Book
Returns a new instance of Book.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/creeker/book.rb', line 17 def initialize path, = {} check_file_extension = .fetch(:check_file_extension, true) if check_file_extension extension = File.extname([:original_filename] || path).downcase raise 'Not a valid file format.' unless (['.xlsx', '.xlsm'].include? extension) end if [:remote] zipfile = Tempfile.new("file") zipfile.binmode zipfile.write(HTTParty.get(path).body) zipfile.close path = zipfile.path end @files = Zip::File.open(path) @shared_strings = SharedStrings.new(self, [:multi_thread]) end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
10 11 12 |
# File 'lib/creeker/book.rb', line 10 def files @files end |
#shared_strings ⇒ Object (readonly)
Returns the value of attribute shared_strings.
10 11 12 |
# File 'lib/creeker/book.rb', line 10 def shared_strings @shared_strings end |
#sheets ⇒ Object (readonly)
Returns the value of attribute sheets.
10 11 12 |
# File 'lib/creeker/book.rb', line 10 def sheets @sheets end |
Instance Method Details
#base_date ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/creeker/book.rb', line 63 def base_date @base_date ||= begin # Default to 1900 (minus one day due to excel quirk) but use 1904 if # it's set in the Workbook's workbookPr # http://msdn.microsoft.com/en-us/library/ff530155(v=office.12).aspx result = DATE_1900 # default doc = @files.file.open "xl/workbook.xml" xml = Nokogiri::XML::Document.parse doc xml.css('workbookPr[date1904]').each do |workbookPr| if workbookPr['date1904'] =~ /true|1/i result = DATE_1904 break end end result end end |
#close ⇒ Object
59 60 61 |
# File 'lib/creeker/book.rb', line 59 def close @files.close end |
#style_types ⇒ Object
55 56 57 |
# File 'lib/creeker/book.rb', line 55 def style_types @style_types ||= Creeker::Styles.new(self).style_types end |