loady 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,6 +2,7 @@ pkg/*
2
2
  *.gem
3
3
  .bundle
4
4
  .idea
5
+ Gemfile.lock
5
6
  *#
6
7
  .#*
7
8
  *~
data/README.rdoc CHANGED
@@ -8,13 +8,13 @@ It works with ruby 1.9. It uses ruby's CSV library to parse rows.
8
8
 
9
9
  gem install loady
10
10
 
11
- Use bundler. Include the gem in your Gemfile:
11
+ Or include the gem in your Gemfile:
12
12
 
13
13
  gem 'loady'
14
14
 
15
15
  == Use
16
16
 
17
- If an error occurs, Loady will continue reading the file, ignoring problems rows and logging a warning for each.
17
+ If an error occurs, Loady will continue reading the file, ignoring problem rows and logging a warning for each.
18
18
 
19
19
  By default, messages are logged to the standard output.
20
20
 
@@ -29,7 +29,7 @@ Skip the first row and log to a file:
29
29
 
30
30
  logger = Logger.new "/your/file.log"
31
31
 
32
- Loady.csv "/your/file.csv", :logger => logger, :skip_first_row => true do |row|
32
+ Loady.csv "/your/file.csv", logger: logger, skip_first_row: true do |row|
33
33
  # do some stuff for each row
34
34
  end
35
35
 
@@ -41,13 +41,13 @@ Name your attributes:
41
41
 
42
42
  Load a tab-delimited file:
43
43
 
44
- Loady.csv "/your/file.tab", :col_sep => "\t" do |row|
44
+ Loady.csv "/your/file.tab", col_sep: "\t" do |row|
45
45
  # go bananas
46
46
  end
47
47
 
48
48
  == Development
49
49
 
50
- git clone git://github.com/stackpilot/loady.git
50
+ git clone git://github.com/teeparham/loady.git
51
51
  cd loady
52
52
  bundle
53
- bundle exec rake test
53
+ bundle exec rake
data/Rakefile CHANGED
@@ -5,7 +5,10 @@ require 'bundler'
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
7
  require 'rake/testtask'
8
+
9
+ task default: [:test]
10
+
8
11
  Rake::TestTask.new(:test) do |t|
9
- t.test_files = ['test/**/*.rb']
12
+ t.test_files = %w(test/**/*.rb)
10
13
  t.verbose = false
11
14
  end
data/lib/loady.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'loady/array'
2
2
  require 'loady/csv_loader'
3
+ require 'loady/memory_logger'
3
4
 
4
5
  module Loady
5
6
  def csv(*args, &block)
data/lib/loady/array.rb CHANGED
@@ -2,13 +2,13 @@ class Array
2
2
 
3
3
  # usage:
4
4
  # ['john', 'doe'].to_attributes([:first, :last])
5
- # => { :first => 'john', :last => 'doe' }
5
+ # => { first: 'john', last: 'doe' }
6
6
  #
7
7
  # options:
8
- # :strip => false -- default = true
9
- # -- array values must be strings if :strip is true
8
+ # strip: false -- default = true
9
+ # -- array values must be strings if :strip is true
10
10
  def to_attributes(names, options={})
11
- options = {:strip => true}.merge(options)
11
+ options = { strip: true }.merge(options)
12
12
 
13
13
  h = {}
14
14
 
@@ -0,0 +1,14 @@
1
+ class MemoryLogger
2
+ attr_reader :messages
3
+
4
+ def initialize
5
+ @messages = []
6
+ end
7
+
8
+ def info(message)
9
+ @messages << message
10
+ end
11
+
12
+ alias_method :warn, :info
13
+ alias_method :error, :info
14
+ end
data/lib/loady/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Loady
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/loady.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.version = Loady::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Tee Parham"]
10
- s.email = ["tee@stackpilot.com"]
11
- s.homepage = "http://github.com/stackpilot/loady"
10
+ s.email = ["tee@neighborland.com"]
11
+ s.homepage = "http://github.com/teeparham/loady"
12
12
  s.summary = %q{CSV file loader with simple logging}
13
13
  s.description = %q{CSV file loader with simple logging}
14
14
 
@@ -2,51 +2,47 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  class CsvLoaderTest < Test::Unit::TestCase
4
4
 
5
- context "Simple class" do
5
+ should "read file1" do
6
+ monkeys = []
6
7
 
7
- should "read file1" do
8
- monkeys = []
8
+ Loady::CsvLoader.read "test/csv/file1.csv", skip_first_row: true do |row|
9
+ monkeys << { name: row[0], year: row[1] }
10
+ end
11
+
12
+ assert_equal monkeys.count, 10, "total rows read"
13
+ assert_equal monkeys[0][:name], "Bubbles", "first row name"
14
+ assert_equal monkeys[0][:year], "2000", "first row year"
15
+ assert_equal monkeys[9][:name], "King Kong", "last row name"
16
+ assert_equal monkeys[9][:year], "1933", "last row year"
17
+ end
9
18
 
10
- Loady::CsvLoader.read "test/csv/file1.csv", :skip_first_row => true do |row|
11
- monkeys << { :name => row[0], :year => row[1] }
12
- end
19
+ should "read file2 with logger using named attributes" do
20
+ logger = Logger.new("/dev/null")
21
+ monkeys = []
13
22
 
14
- assert_equal monkeys.count, 10, "total rows read"
15
- assert_equal monkeys[0][:name], "Bubbles", "first row name"
16
- assert_equal monkeys[0][:year], "2000", "first row year"
17
- assert_equal monkeys[9][:name], "King Kong", "last row name"
18
- assert_equal monkeys[9][:year], "1933", "last row year"
23
+ Loady.csv "test/csv/file2.csv", logger: logger do |row|
24
+ monkeys << row.to_attributes([:name, :year])
19
25
  end
20
26
 
21
- should "read file2 with logger using named attributes" do
22
- logger = Logger.new("/dev/null")
23
- monkeys = []
27
+ assert_equal monkeys.count, 10, "total rows read"
28
+ assert_equal monkeys[0][:name], "Bubbles", "first row name"
29
+ assert_equal monkeys[0][:year], "2000", "first row year"
30
+ assert_equal monkeys[9][:name], "King Kong", "last row name"
31
+ assert_equal monkeys[9][:year], "1933", "last row year"
32
+ end
24
33
 
25
- Loady.csv "test/csv/file2.csv", :logger => logger do |row|
26
- monkeys << row.to_attributes([:name, :year])
27
- end
34
+ should "read file3, a tab-delimited file" do
35
+ monkeys = []
28
36
 
29
- assert_equal monkeys.count, 10, "total rows read"
30
- assert_equal monkeys[0][:name], "Bubbles", "first row name"
31
- assert_equal monkeys[0][:year], "2000", "first row year"
32
- assert_equal monkeys[9][:name], "King Kong", "last row name"
33
- assert_equal monkeys[9][:year], "1933", "last row year"
34
- end
35
-
36
- should "read file3, a tab-delimited file" do
37
- monkeys = []
38
-
39
- Loady.csv "test/csv/file3.dat", :skip_first_row => true, :col_sep => "\t" do |row|
40
- monkeys << { :name => row[0], :year => row[1] }
41
- end
42
-
43
- assert_equal monkeys.count, 10, "total rows read"
44
- assert_equal monkeys[0][:name], "Bubbles", "first row name"
45
- assert_equal monkeys[0][:year], "2000", "first row year"
46
- assert_equal monkeys[9][:name], "King Kong", "last row name"
47
- assert_equal monkeys[9][:year], "1933", "last row year"
37
+ Loady.csv "test/csv/file3.dat", skip_first_row: true, col_sep: "\t" do |row|
38
+ monkeys << { name: row[0], year: row[1] }
48
39
  end
49
-
50
- end
51
40
 
41
+ assert_equal monkeys.count, 10, "total rows read"
42
+ assert_equal monkeys[0][:name], "Bubbles", "first row name"
43
+ assert_equal monkeys[0][:year], "2000", "first row year"
44
+ assert_equal monkeys[9][:name], "King Kong", "last row name"
45
+ assert_equal monkeys[9][:year], "1933", "last row year"
46
+ end
47
+
52
48
  end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
+
3
+ class MemoryLoggerTest < Test::Unit::TestCase
4
+ context "memory logger" do
5
+ setup do
6
+ @logger = MemoryLogger.new
7
+ end
8
+
9
+ should "have no messages" do
10
+ assert_empty @logger.messages
11
+ end
12
+
13
+ should "log warning" do
14
+ @logger.warn "message"
15
+ assert_equal "message", @logger.messages.first.to_s
16
+ end
17
+
18
+ should "log info" do
19
+ @logger.info "message"
20
+ assert_equal "message", @logger.messages.first.to_s
21
+ end
22
+
23
+ should "log error" do
24
+ @logger.error "message"
25
+ assert_equal "message", @logger.messages.first.to_s
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loady
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-17 00:00:00.000000000 Z
12
+ date: 2012-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
16
- requirement: &2153048400 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153048400
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: shoulda
27
- requirement: &2153047980 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2153047980
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &2153047560 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2153047560
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: CSV file loader with simple logging
48
63
  email:
49
- - tee@stackpilot.com
64
+ - tee@neighborland.com
50
65
  executables: []
51
66
  extensions: []
52
67
  extra_rdoc_files: []
@@ -54,12 +69,12 @@ files:
54
69
  - .gitignore
55
70
  - .rvmrc
56
71
  - Gemfile
57
- - Gemfile.lock
58
72
  - README.rdoc
59
73
  - Rakefile
60
74
  - lib/loady.rb
61
75
  - lib/loady/array.rb
62
76
  - lib/loady/csv_loader.rb
77
+ - lib/loady/memory_logger.rb
63
78
  - lib/loady/version.rb
64
79
  - loady.gemspec
65
80
  - test/csv/file1.csv
@@ -68,7 +83,8 @@ files:
68
83
  - test/test_csv_loader.rb
69
84
  - test/test_helper.rb
70
85
  - test/test_loady.rb
71
- homepage: http://github.com/stackpilot/loady
86
+ - test/test_memory_logger.rb
87
+ homepage: http://github.com/teeparham/loady
72
88
  licenses: []
73
89
  post_install_message:
74
90
  rdoc_options: []
@@ -80,15 +96,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
96
  - - ! '>='
81
97
  - !ruby/object:Gem::Version
82
98
  version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 3415913565641349533
83
102
  required_rubygems_version: !ruby/object:Gem::Requirement
84
103
  none: false
85
104
  requirements:
86
105
  - - ! '>='
87
106
  - !ruby/object:Gem::Version
88
107
  version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 3415913565641349533
89
111
  requirements: []
90
112
  rubyforge_project: loady
91
- rubygems_version: 1.8.10
113
+ rubygems_version: 1.8.24
92
114
  signing_key:
93
115
  specification_version: 3
94
116
  summary: CSV file loader with simple logging
@@ -99,3 +121,4 @@ test_files:
99
121
  - test/test_csv_loader.rb
100
122
  - test/test_helper.rb
101
123
  - test/test_loady.rb
124
+ - test/test_memory_logger.rb
data/Gemfile.lock DELETED
@@ -1,20 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- loady (0.3.0)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- rake (0.9.2.2)
10
- shoulda (2.11.3)
11
- test-unit (2.1.2)
12
-
13
- PLATFORMS
14
- ruby
15
-
16
- DEPENDENCIES
17
- loady!
18
- rake
19
- shoulda
20
- test-unit