Class: Creek::Book
- Inherits:
-
Object
- Object
- Creek::Book
- Defined in:
- lib/creek/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.
-
#with_headers ⇒ Object
readonly
Returns the value of attribute with_headers.
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.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/creek/book.rb', line 18 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 path = download_file(path) if [:remote] @files = Zip::File.open(path) @shared_strings = SharedStrings.new(self) @with_headers = .fetch(:with_headers, false) end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
10 11 12 |
# File 'lib/creek/book.rb', line 10 def files @files end |
#shared_strings ⇒ Object (readonly)
Returns the value of attribute shared_strings.
10 11 12 |
# File 'lib/creek/book.rb', line 10 def shared_strings @shared_strings end |
#sheets ⇒ Object (readonly)
Returns the value of attribute sheets.
10 11 12 |
# File 'lib/creek/book.rb', line 10 def sheets @sheets end |
#with_headers ⇒ Object (readonly)
Returns the value of attribute with_headers.
10 11 12 |
# File 'lib/creek/book.rb', line 10 def with_headers @with_headers end |
Instance Method Details
#base_date ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/creek/book.rb', line 68 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
64 65 66 |
# File 'lib/creek/book.rb', line 64 def close @files.close end |
#style_types ⇒ Object
60 61 62 |
# File 'lib/creek/book.rb', line 60 def style_types @style_types ||= Creek::Styles.new(self).style_types end |