attribution 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/attribution.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "attribution"
5
- gem.version = "0.2.0"
5
+ gem.version = "0.3.0"
6
6
  gem.authors = ["Paul Barry"]
7
7
  gem.email = ["mail@paulbarry.com"]
8
8
  gem.description = %q{Add attributes to Ruby objects}
9
9
  gem.summary = %q{Add attributes to Ruby objects}
10
- gem.homepage = ""
10
+ gem.homepage = "http://github.com/pjb3/attribution"
11
11
 
12
12
  gem.files = `git ls-files`.split($/)
13
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/attribution.rb CHANGED
@@ -99,6 +99,7 @@ module Attribution
99
99
  when Date then arg
100
100
  when Time, DateTime then arg.to_date
101
101
  when String then Date.parse(arg)
102
+ when Hash then Date.new(*arg.slice(:year, :month, :day).values.map(&:to_i))
102
103
  else raise ArgumentError.new("can't convert #{arg.class} to Date")
103
104
  end
104
105
  instance_variable_set("@#{attr}", v)
@@ -112,6 +113,7 @@ module Attribution
112
113
  when Date, DateTime then arg.to_time
113
114
  when Time then arg
114
115
  when String then Time.parse(arg)
116
+ when Hash then Time.new(*arg.slice(:year, :month, :day, :hour, :min, :sec, :utc_offset).values.map(&:to_i))
115
117
  else raise ArgumentError.new("can't convert #{arg.class} to Time")
116
118
  end
117
119
  instance_variable_set("@#{attr}", v)
@@ -1,3 +1,3 @@
1
1
  module Attribution
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -114,4 +114,14 @@ class AttributionTest < Test::Unit::TestCase
114
114
  ], Chapter.attributes
115
115
  assert_equal({ :id => nil, :number => 1, :title => nil, :page_number => nil, :book_id => nil }, chapter.attributes)
116
116
  end
117
+
118
+ def test_date_hash
119
+ book = Book.new(:published_on => { :year => '2013', :month => '03', :day => '17' })
120
+ assert_equal Date.parse('2013-03-17'), book.published_on
121
+ end
122
+
123
+ def test_time_hash
124
+ book = Book.new(:created_at => { :year => '2013', :month => '03', :day => '17', :hour => '07', :min => '30', :sec => '11', :utc_offset => '3600' })
125
+ assert_equal Time.parse('2013-03-17 07:30:11 +01:00'), book.created_at
126
+ end
117
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribution
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -59,7 +59,7 @@ files:
59
59
  - lib/attribution.rb
60
60
  - lib/attribution/version.rb
61
61
  - test/attribution_test.rb
62
- homepage: ''
62
+ homepage: http://github.com/pjb3/attribution
63
63
  licenses: []
64
64
  post_install_message:
65
65
  rdoc_options: []
@@ -79,10 +79,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 1.8.24
82
+ rubygems_version: 1.8.25
83
83
  signing_key:
84
84
  specification_version: 3
85
85
  summary: Add attributes to Ruby objects
86
86
  test_files:
87
87
  - test/attribution_test.rb
88
- has_rdoc: