split_date_time 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 059d33ea86c2694f4aa88795eaa0cee755198b14
4
- data.tar.gz: 05894f3fd4f4a598861c079671747b4a87931ff6
3
+ metadata.gz: 196ee61038b6c87cf4ff8aa83ca2ae108ccc1352
4
+ data.tar.gz: 7d492f0509048472fc26f91c87ae25cafc0f2536
5
5
  SHA512:
6
- metadata.gz: affc6fd427f2619fa9a4964b774f957e4b1d5471f82d87355ffcc41564400ae2be99ec1f256fd39313ea281e47a4e7c66c101d708fb8b87246c5e6c8a9efcd6c
7
- data.tar.gz: 5bc1f8f2e6ab148bc3055d5166086a66ecb96403a1b67509703da77b19e58e19806654edc5b25e659b0a1ba67040095a2b2985e51ac23d1bda088e8af0d50626
6
+ metadata.gz: 57e584fcdb95bbebd19d29a667300d25b227926f676a2491f1477912a28daadf8bce29ee887609adff5a3097e1bf3d40b98972f71ea43cb48db33939cc8ae6d7
7
+ data.tar.gz: da315ba011ec2c46542b301da3e90f0ad1d6c4c6aa7ebb7e28176eee6c9144ca9876eb326029f280655155366442d238a0d0e711ab7e3dc1498bf7cde3b59ca3
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.swp
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # SplitDateTime
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/ccallebs/split_date_time.png)](https://codeclimate.com/github/ccallebs/split_date_time)
4
+ [![Code Climate](https://codeclimate.com/github/ccallebs/split_date_time/coverage.png)](https://codeclimate.com/github/ccallebs/split_date_time)
5
+
3
6
  A simple gem that allows you to split a DateTime field into a Date and a Time field for separate processing.
4
7
 
5
8
  ## Installation
@@ -34,21 +34,24 @@ module SplitDateTime
34
34
 
35
35
  module ClassMethods
36
36
  def split_date_time(field, options = {})
37
- define_split_accessors(field, options[:prefix])
37
+ define_split_accessors(field, options[:prefix], options[:date_format], options[:time_format])
38
38
  define_concatenation_callback(field, options[:prefix])
39
39
  end
40
40
 
41
- def define_split_accessors(field, prefix = nil)
41
+ def define_split_accessors(field, prefix = nil, date_format = nil, time_format = nil)
42
+ time_format ||= '%H:%M'
43
+ date_format ||= '%m/%d/%Y'
44
+
42
45
  define_method Naming.time_getter(field, prefix) do
43
46
  field_val = send(field)
44
- field_val.strftime('%H:%M') if field_val.present?
47
+ field_val.strftime(time_format) if field_val.present?
45
48
  end
46
49
  define_method Naming.time_setter(field, prefix) do |val|
47
50
  instance_variable_set :"@#{Naming.time_getter(field, prefix)}", val
48
51
  end
49
52
  define_method Naming.date_getter(field, prefix) do
50
53
  field_val = send(field)
51
- field_val.strftime('%m/%d/%Y') if field_val.present?
54
+ field_val.strftime(date_format) if field_val.present?
52
55
  end
53
56
  define_method Naming.date_setter(field, prefix) do |val|
54
57
  instance_variable_set :"@#{Naming.date_getter(field, prefix)}", val
@@ -1,3 +1,3 @@
1
1
  module SplitDateTime
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -5,10 +5,11 @@ describe SplitDateTime::Splitter do
5
5
  class TestClass
6
6
  include SplitDateTime::Splitter
7
7
 
8
- attr_accessor :test_field_1, :test_field_2
8
+ attr_accessor :test_field_1, :test_field_2, :custom_format
9
9
 
10
10
  split_date_time :test_field_1
11
11
  split_date_time :test_field_2, prefix: :other
12
+ split_date_time :custom_format, date_format: '%m/%y', time_format: '%H:%M %p'
12
13
  end
13
14
 
14
15
  context '#initialization' do
@@ -44,6 +45,12 @@ describe SplitDateTime::Splitter do
44
45
  subject.should respond_to(:other_date)
45
46
  subject.should respond_to(:other_time)
46
47
  end
48
+
49
+ it 'uses custom date format when provided' do
50
+ subject.custom_format = DateTime.parse("12/12/2014 01:15:24 AM")
51
+ expect(subject.custom_format_date).to eq('12/14')
52
+ expect(subject.custom_format_time).to eq('01:15 AM')
53
+ end
47
54
  end
48
55
 
49
56
  context '#callbacks' do
@@ -64,13 +71,13 @@ describe SplitDateTime::Splitter do
64
71
  it 'should show field as modified if both date and time are touched' do
65
72
  subject.test_field_1_date = '03/03/2014'
66
73
  subject.test_field_1_time = '01:15'
67
- subject.test_field_1_modified?.should be_true
74
+ expect(subject.test_field_1_modified?).to eq(true)
68
75
  end
69
76
 
70
77
  it 'should show field as modified if only date or time were touched' do
71
78
  subject.test_field_1 = DateTime.parse("03/03/2014 01:15:24 AM")
72
79
  subject.test_field_1_date = '05/05/2014'
73
- subject.test_field_1_modified?.should be_true
80
+ expect(subject.test_field_1_modified?).to eq(true)
74
81
  end
75
82
  end
76
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split_date_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Callebs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-01 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.2.1
136
+ rubygems_version: 2.2.2
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Allows DateTime fields to be split into a Date field and a Time field.