easybill 0.2.22 → 0.2.23

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: 7de497b23a234c45715ca9631c86faa14639761e
4
- data.tar.gz: 3f530737b1893119d3f2efb48ff8264a42375a13
3
+ metadata.gz: 4a20a6e41d851f9da4cebe2894c5ac9de32a7bb4
4
+ data.tar.gz: 5d2e4fb5d06e35dbf401af95c1dac13c5fde6774
5
5
  SHA512:
6
- metadata.gz: 72b3c422836b5207212d3c5d7d40fde229f09dc3f74a2caaac741ca1ecce6e44e9170ea0b3b20919d24c4d69e4259704235cbfcb11fa613d42d22a15bb08897f
7
- data.tar.gz: e25b2c7594fe262072360d35e141bb7f8017e5cc67bed27878a92e88c853f16c6b3ee9e46320d52b0ac722502855462c515c6aa1e9ad41dd9bd936567896cb5d
6
+ metadata.gz: 708e8e109062f5980559fd875cf5e7123bfd893d43bf6daa0cfed4ee964d3c964a3ced0fc099f2b3377e4cd46369b45c621217e7c5d416f9267f87ab5a4c27ed
7
+ data.tar.gz: 6d142049619a75bec92bac79c187b226a2c3d74c8e10612536f655852464b7de206f8d5703efa9360d4c933faf87f4eff2dc34dab10e6b0f31798435b1e751f5
@@ -1,5 +1,6 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-04-27 16:05:46 +0200 using RuboCop version 0.30.1.
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-10-05 10:47:47 +0200 using RuboCop version 0.34.2.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
@@ -18,10 +19,10 @@ Metrics/ClassLength:
18
19
  Metrics/CyclomaticComplexity:
19
20
  Max: 7
20
21
 
21
- # Offense count: 21
22
+ # Offense count: 19
22
23
  # Configuration parameters: AllowURI, URISchemes.
23
24
  Metrics/LineLength:
24
- Max: 197
25
+ Max: 143
25
26
 
26
27
  # Offense count: 2
27
28
  # Configuration parameters: CountComments.
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'php_serialize'
2
3
 
3
4
  module Easybill
@@ -5,16 +6,13 @@ module Easybill
5
6
  class ParseError < StandardError; end
6
7
 
7
8
  def service_period
8
- plain_service_date = PHP.unserialize(service_date)
9
+ parsed = parse_service_date
10
+ return '' if parsed.nil?
9
11
 
10
- if plain_service_date.nil?
11
- ''
12
+ if parsed.key?('serviceDateFrom')
13
+ "#{parse_date(parsed['serviceDateFrom'])} - #{parse_date(parsed['serviceDateThru'])}"
12
14
  else
13
- if plain_service_date.key?('serviceDateFrom')
14
- "#{parse_date(plain_service_date['serviceDateFrom'])} - #{parse_date(plain_service_date['serviceDateThru'])}"
15
- else
16
- plain_service_date['serviceDateString']
17
- end
15
+ parsed['serviceDateString']
18
16
  end
19
17
  rescue TypeError => e
20
18
  raise ParseError, e
@@ -34,5 +32,12 @@ module Easybill
34
32
  def parse_date(date)
35
33
  Date.parse(date).strftime('%d.%m.%Y')
36
34
  end
35
+
36
+ def parse_service_date
37
+ return nil if service_date.nil?
38
+ JSON.parse(service_date)
39
+ rescue JSON::ParserError
40
+ PHP.unserialize(service_date)
41
+ end
37
42
  end
38
43
  end
@@ -1,3 +1,3 @@
1
1
  module Easybill
2
- VERSION = '0.2.22'.freeze
2
+ VERSION = '0.2.23'.freeze
3
3
  end
@@ -2,46 +2,75 @@ require 'spec_helper'
2
2
 
3
3
  describe Easybill::Document do
4
4
  describe '#service_period' do
5
- subject { document.service_period }
5
+ subject { described_class.new('service_date' => service_date).service_period }
6
6
 
7
7
  context 'when a valid serviceDateString was returned' do
8
- let(:document) { described_class.new('service_date' => "a:1:{s:17:\"serviceDateString\";s:23:\"01.05.2014 - 15.05.2014\";}") }
8
+ context 'PHP-serialized object' do
9
+ let(:service_date) { 'a:1:{s:17:"serviceDateString";s:23:"01.05.2014 - 15.05.2014";}' }
9
10
 
10
- it { is_expected.to eq('01.05.2014 - 15.05.2014') }
11
+ it { is_expected.to eq('01.05.2014 - 15.05.2014') }
12
+ end
13
+
14
+ context 'JSON' do
15
+ let(:service_date) do
16
+ '{"serviceDateType":"1","serviceDateString":"01.08.2015 - 31.08.2015"}'
17
+ end
18
+
19
+ it { is_expected.to eq('01.08.2015 - 31.08.2015') }
20
+ end
11
21
  end
12
22
 
13
23
  context 'when serviceDateString includes a date range' do
14
- let(:document) { described_class.new('service_date' => "a:3:{s:15:\"serviceDateType\";s:1:\"1\";s:15:\"serviceDateFrom\";s:10:\"2014-07-01\";s:15:\"serviceDateThru\";s:10:\"2014-07-04\";}") }
24
+ context 'PHP-serialized object' do
25
+ let(:service_date) do
26
+ 'a:3:{s:15:"serviceDateType";s:1:"1";s:15:"serviceDateFrom";s:10:"2014-07-01";s:15:"serviceDateThru";s:10:"2014-07-04";}'
27
+ end
28
+
29
+ it { is_expected.to eq('01.07.2014 - 04.07.2014') }
30
+ end
15
31
 
16
- it { is_expected.to eq('01.07.2014 - 04.07.2014') }
32
+ context 'JSON' do
33
+ let(:service_date) do
34
+ '{"serviceDateType":"1","serviceDateFrom":"2014-07-01","serviceDateThru":"2014-07-04"}'
35
+ end
36
+
37
+ it { is_expected.to eq('01.07.2014 - 04.07.2014') }
38
+ end
39
+ end
40
+
41
+ context 'when a nil serviceDateString was returned' do
42
+ let(:service_date) { nil }
43
+
44
+ it { is_expected.to eq('') }
17
45
  end
18
46
 
19
47
  context 'when a null serviceDateString was returned' do
20
- let(:document) { described_class.new('service_date' => 'N;') }
48
+ let(:service_date) { 'N;' }
21
49
 
22
50
  it { is_expected.to eq('') }
23
51
  end
24
52
 
25
53
  context 'when parsing data is malformed' do
26
- let(:document) { described_class.new('service_date' => '{}') }
54
+ let(:service_date) { '{invalid' }
27
55
 
28
56
  it 'throws Easybill::Document::ParseError exception' do
29
- expect { subject }.to raise_error(Easybill::Document::ParseError, 'Unable to unserialize type \'{\'')
57
+ expect { subject }
58
+ .to raise_error(Easybill::Document::ParseError, 'Unable to unserialize type \'{\'')
30
59
  end
31
60
  end
32
61
  end
33
62
 
34
63
  describe '#service_period_end' do
35
- subject { document.service_period_end }
64
+ subject { described_class.new('service_date' => service_date).service_period_end }
36
65
 
37
66
  context 'when a valid serviceDateString was returned' do
38
- let(:document) { described_class.new('service_date' => "a:1:{s:17:\"serviceDateString\";s:23:\"01.05.2014 - 15.05.2014\";}") }
67
+ let(:service_date) { 'a:1:{s:17:"serviceDateString";s:23:"01.05.2014 - 15.05.2014";}' }
39
68
 
40
69
  it { is_expected.to eq(Date.new(2014, 5, 15)) }
41
70
  end
42
71
 
43
72
  context 'when a null serviceDateString was returned' do
44
- let(:document) { described_class.new('service_date' => 'N;') }
73
+ let(:service_date) { 'N;' }
45
74
 
46
75
  it { is_expected.to be_nil }
47
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easybill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - ad2games GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-30 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sekken