Permalink
Browse files

rejiggered date and time parsing to be ruby 1.9 friendly

  • Loading branch information...
1 parent 80738f2 commit bdb70ae6ae0a4ba11038a42b860082839ed19c85 @jszmajda jszmajda committed Dec 1, 2011
Showing with 83 additions and 11 deletions.
  1. +55 −0 .rvmrc
  2. +1 −1 Gemfile
  3. +15 −8 Gemfile.lock
  4. +1 −1 lib/amazon_seller_central/feedback_page.rb
  5. +1 −1 lib/amazon_seller_central/inventory_page.rb
  6. +10 −0 lib/amazon_seller_central/page.rb
View
55 .rvmrc
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
+environment_id="ruby-1.9.2-p290"
+
+#
+# Uncomment following line if you want options to be set only for given project.
+#
+# PROJECT_JRUBY_OPTS=( --1.9 )
+
+#
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+#
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
+ then
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
+ fi
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ if ! rvm --create "$environment_id"
+ then
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ fi
+fi
+
+#
+# If you use an RVM gemset file to install a list of gems (*.gems), you can have
+# it be automatically loaded. Uncomment the following and adjust the filename if
+# necessary.
+#
+# filename=".gems"
+# if [[ -s "$filename" ]]
+# then
+# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
+# fi
+
+# If you use bundler, this might be useful to you:
+# if command -v bundle && [[ -s Gemfile ]]
+# then
+# bundle install
+# fi
+
+
View
@@ -20,5 +20,5 @@ group :development do
gem 'ffi'
gem 'faker'
gem 'fakeweb'
- gem 'ruby-debug'
+ gem 'ruby-debug19'
end
View
@@ -1,7 +1,8 @@
GEM
remote: http://rubygems.org/
specs:
- columnize (0.3.2)
+ archive-tar-minitar (0.5.2)
+ columnize (0.3.5)
diff-lcs (1.1.2)
faker (0.9.5)
i18n (~> 0.4)
@@ -18,7 +19,8 @@ GEM
git (>= 1.2.5)
rake
libnotify (0.5.6)
- linecache (0.43)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
mechanize (1.0.0)
nokogiri (>= 1.2.1)
nokogiri (1.4.4)
@@ -34,11 +36,16 @@ GEM
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
- ruby-debug (0.10.4)
- columnize (>= 0.1)
- ruby-debug-base (~> 0.10.4.0)
- ruby-debug-base (0.10.4)
- linecache (>= 0.3)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
thor (0.14.6)
yard (0.7.2)
@@ -58,5 +65,5 @@ DEPENDENCIES
rb-inotify (>= 0.8.5)
rcov
rspec (~> 2.3.0)
- ruby-debug
+ ruby-debug19
yard
@@ -50,7 +50,7 @@ def load_all_pages
def feedback_row_to_object(row)
data = row.search('.//td').map(&:text)
{
- :date => Time.parse(data[0]),
+ :date => parse_amazon_date(data[0]),
:rating => data[1].to_i,
:comments => data[2].gsub(/\n\nRespond$/,''),
:arrived_on_time => yes_no_nil(data[3]),
@@ -88,7 +88,7 @@ def listing_row_to_object(row)
when 5
l.product_name = txt
when 6
- l.created_at = Time.parse(txt)
+ l.created_at = parse_amazon_time(txt)
when 7
l.quantity = (inputs = td.css('input')).any? ? inputs.first['value'].to_i : txt.to_i
when 8
@@ -23,5 +23,15 @@ def next_page
class NoNextPageAvailableError < StandardError
end
+ protected
+ AZN_DATE_FMT = "%m/%d/%Y"
+ def parse_amazon_time(string)
+ Time.strptime(string, "#{AZN_DATE_FMT} %H:%M:%S")
+ end
+
+ def parse_amazon_date(string)
+ Time.strptime(string, AZN_DATE_FMT)
+ end
+
end
end

0 comments on commit bdb70ae

Please sign in to comment.