glide 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/glide.rb CHANGED
@@ -33,9 +33,9 @@ module Glide
33
33
 
34
34
  def self.calculate_totals(quotes)
35
35
  quotes["total"] = {}
36
- quotes["total"]["tenant_week"] = quotes.map { |e| e[1]["tenant_week"].to_f }.reduce(:+).to_s
37
- quotes["total"]["tenant_month"] = quotes.map { |e| e[1]["tenant_month"].to_f }.reduce(:+).to_s
38
- quotes["total"]["monthly_fee"] = quotes.map { |e| e[1]["monthly_fee"].to_f }.reduce(:+).to_s
36
+ quotes["total"]["tenant_week"] = "%.2f" % quotes.map { |e| e[1]["tenant_week"].to_f }.reduce(:+)
37
+ quotes["total"]["tenant_month"] = "%.2f" % quotes.map { |e| e[1]["tenant_month"].to_f }.reduce(:+)
38
+ quotes["total"]["monthly_fee"] = "%.2f" % quotes.map { |e| e[1]["monthly_fee"].to_f }.reduce(:+)
39
39
 
40
40
  quotes
41
41
  end
data/lib/glide/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Glide
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/glide_spec.rb CHANGED
@@ -17,9 +17,9 @@ describe Glide do
17
17
  quotes.should be_an_instance_of(Hash)
18
18
  quotes["elec"]["monthly_fee"].should eql("30.20")
19
19
  quotes["water"]["tenant_month"].should eql("30.20")
20
- quotes["total"]["monthly_fee"].should eql("181.2")
20
+ quotes["total"]["monthly_fee"].should eql("181.20")
21
21
  quotes["total"]["tenant_week"].should eql("41.82")
22
- quotes["total"]["tenant_month"].should eql("181.2")
22
+ quotes["total"]["tenant_month"].should eql("181.20")
23
23
  end
24
24
 
25
25
  end
@@ -27,7 +27,11 @@ describe Glide do
27
27
  describe "get_service_quote" do
28
28
 
29
29
  it 'should respond with HTTParty response and convert to json' do
30
- HTTParty.should_receive(:get).and_return(Marshal.load("\004\bo:\027HTTParty::Response\n:\r@headerso: HTTParty::Response::Headers\006:\f@header{\017\"\vserver[\006\"\vApache\"\tdate[\006\"\"Sun, 06 May 2012 16:19:40 GMT\"\fexpires[\006\"\"Thu, 19 Nov 1981 08:52:00 GMT\"\vpragma[\006\"\rno-cache\"\023content-length[\006\"\b113\"\021content-type[\006\"\025application/json\"\017connection[\006\"\nclose\"\017set-cookie[\a\"9symfony=2n594frr1c83aldiloljk7erq3; path=/; HttpOnly\"9symfony=6pvq9hfd8elj5n8j2m5ij9kkp7; path=/; HttpOnly\"\022cache-control[\006\"\rno-cache\"\vx-farm[\006\"\nHTTPS:\025@parsed_response{\a\"\fversion\"\rv3.1.1.5\"\fresults{\t\"\020monthly_fee\"\n30.20\"\020tenant_week\"\t6.97\"\nnotes0\"\021tenant_month\"\n30.20:\r@requesto:\026HTTParty::Request\v:\016@last_urio:\017URI::HTTPS\017:\016@fragment0:\n@porti\002\273\001:\n@path\"\036/signup/servicePrice.json:\016@registry0:\016@password0:\f@opaque0:\n@user0:\v@query\"\002/\001key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@host\"\025api.glide.uk.com:\f@scheme\"\nhttps:\r@options{\n:\025follow_redirectsT:\023default_params{\000:\vparserc\025HTTParty::Parser:\nquery{\n:\bkey\"%1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z:\nextra0:\vperiodi\v:\fservice\"\telec:\ftenantsi\006:\nlimiti\n;\020@4:\021@raw_requesto:\023Net::HTTP::Get\f:\021@body_stream0;\020\"j/signup/servicePrice.json?key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@body0;\b{\a\"\017connection[\006\"\nclose\"\thost[\006\"\025api.glide.uk.com:\027@response_has_bodyT:\026@request_has_bodyF:\f@method\"\bGET:\021@http_methodc\023Net::HTTP::Get:\023@last_responseo:\020Net::HTTPOK\r:\022@http_version\"\b1.1:\020@body_existT:\f@socket0;&\"v{\"results\":{\"monthly_fee\":\"30.20\",\"tenant_week\":\"6.97\",\"tenant_month\":\"30.20\",\"notes\":null},\"version\":\"v3.1.1.5\"};\b{\017@\b@\t@\024@\025@\021@\022@\016@\017@\v@\f@\027@\030@\032@\e@!@\"@\035@\036@$@%:\r@message\"\aOK:\n@code\"\b200:\n@readT;&@L:\016@response@J"))
30
+ # HTTParty.should_receive(:get).and_return(Marshal.load("\004\bo:\027HTTParty::Response\n:\r@headerso: HTTParty::Response::Headers\006:\f@header{\017\"\vserver[\006\"\vApache\"\tdate[\006\"\"Sun, 06 May 2012 16:19:40 GMT\"\fexpires[\006\"\"Thu, 19 Nov 1981 08:52:00 GMT\"\vpragma[\006\"\rno-cache\"\023content-length[\006\"\b113\"\021content-type[\006\"\025application/json\"\017connection[\006\"\nclose\"\017set-cookie[\a\"9symfony=2n594frr1c83aldiloljk7erq3; path=/; HttpOnly\"9symfony=6pvq9hfd8elj5n8j2m5ij9kkp7; path=/; HttpOnly\"\022cache-control[\006\"\rno-cache\"\vx-farm[\006\"\nHTTPS:\025@parsed_response{\a\"\fversion\"\rv3.1.1.5\"\fresults{\t\"\020monthly_fee\"\n30.20\"\020tenant_week\"\t6.97\"\nnotes0\"\021tenant_month\"\n30.20:\r@requesto:\026HTTParty::Request\v:\016@last_urio:\017URI::HTTPS\017:\016@fragment0:\n@porti\002\273\001:\n@path\"\036/signup/servicePrice.json:\016@registry0:\016@password0:\f@opaque0:\n@user0:\v@query\"\002/\001key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@host\"\025api.glide.uk.com:\f@scheme\"\nhttps:\r@options{\n:\025follow_redirectsT:\023default_params{\000:\vparserc\025HTTParty::Parser:\nquery{\n:\bkey\"%1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z:\nextra0:\vperiodi\v:\fservice\"\telec:\ftenantsi\006:\nlimiti\n;\020@4:\021@raw_requesto:\023Net::HTTP::Get\f:\021@body_stream0;\020\"j/signup/servicePrice.json?key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@body0;\b{\a\"\017connection[\006\"\nclose\"\thost[\006\"\025api.glide.uk.com:\027@response_has_bodyT:\026@request_has_bodyF:\f@method\"\bGET:\021@http_methodc\023Net::HTTP::Get:\023@last_responseo:\020Net::HTTPOK\r:\022@http_version\"\b1.1:\020@body_existT:\f@socket0;&\"v{\"results\":{\"monthly_fee\":\"30.20\",\"tenant_week\":\"6.97\",\"tenant_month\":\"30.20\",\"notes\":null},\"version\":\"v3.1.1.5\"};\b{\017@\b@\t@\024@\025@\021@\022@\016@\017@\v@\f@\027@\030@\032@\e@!@\"@\035@\036@$@%:\r@message\"\aOK:\n@code\"\b200:\n@readT;&@L:\016@response@J"))
31
+ HTTParty.should_receive(:get) do |args|
32
+ args[1][:query][:service].should eql("elec")
33
+ Marshal.load("\004\bo:\027HTTParty::Response\n:\r@headerso: HTTParty::Response::Headers\006:\f@header{\017\"\vserver[\006\"\vApache\"\tdate[\006\"\"Sun, 06 May 2012 16:19:40 GMT\"\fexpires[\006\"\"Thu, 19 Nov 1981 08:52:00 GMT\"\vpragma[\006\"\rno-cache\"\023content-length[\006\"\b113\"\021content-type[\006\"\025application/json\"\017connection[\006\"\nclose\"\017set-cookie[\a\"9symfony=2n594frr1c83aldiloljk7erq3; path=/; HttpOnly\"9symfony=6pvq9hfd8elj5n8j2m5ij9kkp7; path=/; HttpOnly\"\022cache-control[\006\"\rno-cache\"\vx-farm[\006\"\nHTTPS:\025@parsed_response{\a\"\fversion\"\rv3.1.1.5\"\fresults{\t\"\020monthly_fee\"\n30.20\"\020tenant_week\"\t6.97\"\nnotes0\"\021tenant_month\"\n30.20:\r@requesto:\026HTTParty::Request\v:\016@last_urio:\017URI::HTTPS\017:\016@fragment0:\n@porti\002\273\001:\n@path\"\036/signup/servicePrice.json:\016@registry0:\016@password0:\f@opaque0:\n@user0:\v@query\"\002/\001key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@host\"\025api.glide.uk.com:\f@scheme\"\nhttps:\r@options{\n:\025follow_redirectsT:\023default_params{\000:\vparserc\025HTTParty::Parser:\nquery{\n:\bkey\"%1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z:\nextra0:\vperiodi\v:\fservice\"\telec:\ftenantsi\006:\nlimiti\n;\020@4:\021@raw_requesto:\023Net::HTTP::Get\f:\021@body_stream0;\020\"j/signup/servicePrice.json?key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@body0;\b{\a\"\017connection[\006\"\nclose\"\thost[\006\"\025api.glide.uk.com:\027@response_has_bodyT:\026@request_has_bodyF:\f@method\"\bGET:\021@http_methodc\023Net::HTTP::Get:\023@last_responseo:\020Net::HTTPOK\r:\022@http_version\"\b1.1:\020@body_existT:\f@socket0;&\"v{\"results\":{\"monthly_fee\":\"30.20\",\"tenant_week\":\"6.97\",\"tenant_month\":\"30.20\",\"notes\":null},\"version\":\"v3.1.1.5\"};\b{\017@\b@\t@\024@\025@\021@\022@\016@\017@\v@\f@\027@\030@\032@\e@!@\"@\035@\036@$@%:\r@message\"\aOK:\n@code\"\b200:\n@readT;&@L:\016@response@J")
34
+ end
31
35
  Glide.get_service_quote("elec", nil, 6, 1).should eql({"monthly_fee"=>"30.20", "tenant_week"=>"6.97", "notes"=>nil, "tenant_month"=>"30.20"})
32
36
  end
33
37
 
@@ -46,9 +50,9 @@ describe Glide do
46
50
  it "should return totals as new element in hash" do
47
51
  quotes = {"elec" => {"monthly_fee"=>"30.20", "tenant_week"=>"6.97", "notes"=>nil, "tenant_month"=>"30.20"}, "water" => {"monthly_fee"=>"30.20", "tenant_week"=>"6.97", "notes"=>nil, "tenant_month"=>"30.20"}}
48
52
  rt = Glide.calculate_totals(quotes)
49
- rt["total"]["monthly_fee"].should eql("60.4")
53
+ rt["total"]["monthly_fee"].should eql("60.40")
50
54
  rt["total"]["tenant_week"].should eql("13.94")
51
- rt["total"]["tenant_month"].should eql("60.4")
55
+ rt["total"]["tenant_month"].should eql("60.40")
52
56
  end
53
57
  end
54
58
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glide
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Volker Pacher