loady 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/loady/array.rb CHANGED
@@ -1,30 +1,32 @@
1
- class Array
1
+ module Loady
2
+ module Array
2
3
 
3
- # usage:
4
- # ['john', 'doe'].to_attributes([:first, :last])
5
- # => { first: 'john', last: 'doe' }
6
- #
7
- # options:
8
- # strip: false -- default = true
9
- # -- array values must be strings if :strip is true
10
- def to_attributes(names, options={})
11
- options = { strip: true }.merge(options)
4
+ # usage:
5
+ # ['john', 'doe'].to_attributes([:first, :last])
6
+ # => { first: 'john', last: 'doe' }
7
+ #
8
+ # options:
9
+ # strip: false -- default = true
10
+ # -- array values must be strings if :strip is true
11
+ def to_attributes(names, options={})
12
+ options = { strip: true }.merge(options)
12
13
 
13
- h = {}
14
+ h = {}
14
15
 
15
- names.each_with_index do |name, i|
16
- if i < self.size
17
- if options[:strip] && self[i]
18
- h[name] = self[i].strip
16
+ names.each_with_index do |name, i|
17
+ if i < self.size
18
+ if options[:strip] && self[i]
19
+ h[name] = self[i].strip
20
+ else
21
+ h[name] = self[i]
22
+ end
19
23
  else
20
- h[name] = self[i]
24
+ h[name] = nil
21
25
  end
22
- else
23
- h[name] = nil
24
26
  end
27
+
28
+ h
25
29
  end
26
30
 
27
- h
28
31
  end
29
-
30
- end
32
+ end
@@ -33,10 +33,10 @@ module Loady
33
33
  line_number += 1
34
34
 
35
35
  row = CSV.parse(line, options)[0]
36
+ row.extend Loady::Array
36
37
 
37
38
  unless row.empty?
38
39
  yield row
39
-
40
40
  success += 1
41
41
  end
42
42
  rescue Exception => message
data/lib/loady/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Loady
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/test/test_loady.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  class LoadyTest < Test::Unit::TestCase
4
- context "array" do
4
+ context "#to_attributes" do
5
5
 
6
6
  should "return named attributes" do
7
7
  row = ['Bubbles ', '2000', ' King Kong ']
8
+ row.extend Loady::Array
8
9
  attrs = row.to_attributes [:name, :year, :mom]
9
10
 
10
11
  assert_equal attrs.size, 3
@@ -15,6 +16,7 @@ class LoadyTest < Test::Unit::TestCase
15
16
 
16
17
  should "return named attributes when missing values" do
17
18
  row = ['Bubbles ', '2000']
19
+ row.extend Loady::Array
18
20
  attrs = row.to_attributes [:name, :year, :mom]
19
21
 
20
22
  assert_equal attrs.size, 3
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.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-20 00:00:00.000000000 Z
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
@@ -98,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: 3295273932021347235
101
+ hash: 3713324824844609253
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: 3295273932021347235
110
+ hash: 3713324824844609253
111
111
  requirements: []
112
112
  rubyforge_project: loady
113
113
  rubygems_version: 1.8.24