importex 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ 0.1.1 (Feb 11, 2010)
2
+
3
+ * switching to "spreadsheet" gem instead of "parseexcel"
4
+
5
+
1
6
  0.1.0 (Feb 8, 2010)
2
7
 
3
8
  * initial release
@@ -1,4 +1,4 @@
1
- require 'parseexcel'
1
+ require 'spreadsheet'
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__) + '/importex/base')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/importex/column')
@@ -29,16 +29,18 @@ module Importex
29
29
  # will default to the first one (0). The first row in the Excel document should be the column
30
30
  # names, all rows after that should be records.
31
31
  def self.import(path, worksheet_index = 0)
32
+ Ole::Log.level = Logger::ERROR # to avoid the annoying "root name was" warning
32
33
  @records ||= []
33
- workbook = Spreadsheet::ParseExcel.parse(path)
34
+ workbook = Spreadsheet.open(path)
34
35
  worksheet = workbook.worksheet(worksheet_index)
36
+ worksheet.format_dates!
35
37
  columns = worksheet.row(0).map do |cell|
36
- @columns.detect { |column| column.name == cell.to_s('latin1') }
38
+ @columns.detect { |column| column.name == cell.to_s }
37
39
  end
38
40
  (@columns.select(&:required?) - columns).each do |column|
39
41
  raise MissingColumn, "Column #{column.name} is required but it doesn't exist."
40
42
  end
41
- (1...worksheet.num_rows).each do |row_number|
43
+ (1..worksheet.last_row_index).each do |row_number|
42
44
  row = worksheet.row(row_number)
43
45
  unless row.at(0).nil?
44
46
  attributes = {}
@@ -46,10 +48,8 @@ module Importex
46
48
  if column
47
49
  if row.at(index).nil?
48
50
  value = ""
49
- elsif row.at(index).type == :date
50
- value = row.at(index).date.strftime("%Y-%m-%d %H:%M:%I")
51
51
  else
52
- value = row.at(index).to_s('latin1')
52
+ value = row.at(index).to_s
53
53
  end
54
54
  attributes[column.name] = column.cell_value(value, row_number)
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bates
@@ -9,18 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-08 00:00:00 -08:00
12
+ date: 2010-02-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: parseexcel
16
+ name: spreadsheet
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.5.2
23
+ version: 0.6.4.1
24
24
  version:
25
25
  description: Import an Excel document by creating a Ruby class and passing in an 'xls' file. It will automatically format the columns into specified Ruby objects and raise errors on bad data.
26
26
  email: ryan@railscasts.com