multi-solr 01.02.01 → 01.03.00
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/multi_solr/utils.rb +27 -0
- data/lib/multi_solr/version.rb +1 -1
- data/spec/multi_solr/utils_spec.rb +29 -0
- metadata +7 -5
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module MultiSolr::Utils
|
3
|
+
|
4
|
+
# Convert date-string from Solr into Ruby Time-Instance
|
5
|
+
# Params:
|
6
|
+
# solr_date_string: Date as String ("2012-06-29T12:43:30Z")
|
7
|
+
# returns
|
8
|
+
# Ruby Time-Instance at UTC-Base
|
9
|
+
def solr_datetime_to_ruby_time solr_date_string
|
10
|
+
return nil if solr_date_string.blank?
|
11
|
+
Time.utc solr_date_string[0..3], solr_date_string[5..6], solr_date_string[8..9], solr_date_string[11..12], solr_date_string[14..15], solr_date_string[17..18]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# Convert date-string from Solr into Ruby Time-Instance
|
16
|
+
# Params:
|
17
|
+
# ruby_time_instance: Time-Instance
|
18
|
+
# returns
|
19
|
+
# Time as String in Solr-Format ("2012-06-29T12:43:30Z")
|
20
|
+
def ruby_time_to_solr_datetime ruby_time_instance
|
21
|
+
return nil if ruby_time_instance.nil?
|
22
|
+
ruby_time_instance.strftime('%Y-%m-%dT%H:%M:%SZ')
|
23
|
+
end
|
24
|
+
|
25
|
+
module_function :solr_datetime_to_ruby_time, :ruby_time_to_solr_datetime
|
26
|
+
|
27
|
+
end
|
data/lib/multi_solr/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'multi_solr/utils'
|
3
|
+
|
4
|
+
describe MultiSolr::Utils do
|
5
|
+
|
6
|
+
context "solr_datetime_to_ruby_time" do
|
7
|
+
it "should return nil if becomes a blank value" do
|
8
|
+
MultiSolr::Utils.solr_datetime_to_ruby_time('').should be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return the correct Ruby-Time-Instance" do
|
12
|
+
t = MultiSolr::Utils.solr_datetime_to_ruby_time('2012-06-29T10:30:20Z')
|
13
|
+
t.should be_a(Time)
|
14
|
+
t.should == Time.utc(2012, 06, 29, 10, 30, 20)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
context "ruby_time_to_solr_datetime" do
|
20
|
+
it "should return nil if becomes a nil" do
|
21
|
+
MultiSolr::Utils.ruby_time_to_solr_datetime(nil).should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return the correct Solr-Date-String for Ruby-Time-Instance" do
|
25
|
+
sdate = MultiSolr::Utils.ruby_time_to_solr_datetime(Time.utc(2012, 06, 29, 10, 30, 20))
|
26
|
+
sdate.should == '2012-06-29T10:30:20Z'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi-solr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 01.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 01.03.00
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernd Ledig
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/multi_solr/solr_filter_free_query.rb
|
139
139
|
- lib/multi_solr/solr_filter_simple.rb
|
140
140
|
- lib/multi_solr/timeline_core_handler.rb
|
141
|
+
- lib/multi_solr/utils.rb
|
141
142
|
- lib/multi_solr/version.rb
|
142
143
|
- multi-solr.gemspec
|
143
144
|
- spec/fixtures/solr-testdata.yml
|
@@ -145,6 +146,7 @@ files:
|
|
145
146
|
- spec/multi_solr/search_result_spec.rb
|
146
147
|
- spec/multi_solr/single_core_handler_spec.rb
|
147
148
|
- spec/multi_solr/timeline_core_handler_spec.rb
|
149
|
+
- spec/multi_solr/utils_spec.rb
|
148
150
|
- spec/solr_test_helper.rb
|
149
151
|
- spec/solr_testdata_provider.rb
|
150
152
|
- spec/spec_helper.rb
|