gds-api-adapters 7.5.1 → 7.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gds_api/test_helpers/fact_cave.rb +26 -3
- data/lib/gds_api/version.rb +1 -1
- metadata +4 -4
@@ -8,8 +8,8 @@ module GdsApi
|
|
8
8
|
|
9
9
|
FACT_CAVE_ENDPOINT = Plek.current.find('fact-cave')
|
10
10
|
|
11
|
-
def fact_cave_has_a_fact(slug, value,
|
12
|
-
response = fact_for_slug(slug, value)
|
11
|
+
def fact_cave_has_a_fact(slug, value, options={})
|
12
|
+
response = fact_for_slug(slug, value, options)
|
13
13
|
|
14
14
|
stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
|
15
15
|
.to_return(:body => response.to_json, :status => 200)
|
@@ -28,12 +28,35 @@ module GdsApi
|
|
28
28
|
.to_return(:body => response.to_json, :status => 404)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
# Creates a sample fact-cave response hash.
|
32
|
+
# slug - the slug for the fact (also used to generate the title)
|
33
|
+
# value - the raw value for the fact
|
34
|
+
# options:
|
35
|
+
# formatted_value - the formatted value to use. If unspecified, this is generated based on the type
|
36
|
+
# type - the type of the fact - one of [:currency, :date, :numeric, :text]. Defaults to :text
|
37
|
+
# currency - for the :currency type, an optional currency symbol to prepend to the generated formatted_value
|
38
|
+
# unit - for :numeric types, an optional unit to append to the generated formatted_value
|
39
|
+
def fact_for_slug(slug, value = "Sample Value", options = {})
|
40
|
+
formatted_value = options[:formatted_value]
|
41
|
+
formatted_value ||= case options[:type]
|
42
|
+
when :date
|
43
|
+
value.strftime("%e %B %Y")
|
44
|
+
when :numeric
|
45
|
+
"#{value.to_s}#{options[:unit]}"
|
46
|
+
when :currency
|
47
|
+
"#{options[:currency]}#{sprintf("%.2f", value)}"
|
48
|
+
when :text, nil
|
49
|
+
value
|
50
|
+
else
|
51
|
+
raise "Unknown fact type #{options[:type]}"
|
52
|
+
end
|
53
|
+
|
32
54
|
singular_response_base.merge({
|
33
55
|
"id" => "#{FACT_CAVE_ENDPOINT}/facts/#{slug}",
|
34
56
|
"details" => {
|
35
57
|
"description" => "",
|
36
58
|
"value" => value,
|
59
|
+
"formatted_value" => formatted_value,
|
37
60
|
},
|
38
61
|
"name" => titleize_slug(slug),
|
39
62
|
"updated_at" => Time.now.utc.xmlschema,
|
data/lib/gds_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.6.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-
|
12
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plek
|
@@ -332,7 +332,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
332
332
|
version: '0'
|
333
333
|
segments:
|
334
334
|
- 0
|
335
|
-
hash: -
|
335
|
+
hash: -2580452190386627532
|
336
336
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
337
337
|
none: false
|
338
338
|
requirements:
|
@@ -341,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
341
341
|
version: '0'
|
342
342
|
segments:
|
343
343
|
- 0
|
344
|
-
hash: -
|
344
|
+
hash: -2580452190386627532
|
345
345
|
requirements: []
|
346
346
|
rubyforge_project:
|
347
347
|
rubygems_version: 1.8.23
|