parliament-utils 0.10.0 → 0.10.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: e9a7896fa357fb4169dd17eb9a3583e21013e72e
4
- data.tar.gz: a0609152b4b8509c4017df31665e55c1a169616f
3
+ metadata.gz: 8dd780d300055a0f0b7926bbb9cd7e604c870784
4
+ data.tar.gz: c406ecc6dffe5d212a973565d49c14db6b5a8580
5
5
  SHA512:
6
- metadata.gz: 29f95d2ba7b0eeabaf4826e6bb68f76fa6e37d6341e5187819c7450a33f379ec58e6d440d3912bcd6dddbfbe4bc54bbcb3c5fa036d2502da99436126d1dd7c2b
7
- data.tar.gz: 82c66428fbd06ef442e91afc3875a4d852d9c72ae82c8210b530219cef6808c2f305ebc2fc69297443fce7d05a40e56bf4a427e9291c90320b137eef4e7352d8
6
+ metadata.gz: 76c5da6b9d37ecb2e8d002eb2a535697ac45d9dade4304aee132a6f455e8319cae06f3415cbc9ae4af62ff4583dea6381e3f8a5745a826db450cdc7982b58d8a
7
+ data.tar.gz: 3c39bf491a242dab05ae476c3a26a4b060044e8ea04a74f3a43a50a65677f29374cde618bcf50560a07f084514918fc6b2804652704b058eb9b532645037ad83
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.15.1
4
+ - 2.5.1
5
+ before_install: gem install bundler
6
6
  env:
7
7
  - PARLIAMENT_BASE_URL=https://api.parliament.uk/Staging/fixed-query
@@ -0,0 +1,88 @@
1
+ module Parliament
2
+ module Utils
3
+ module Helpers
4
+ module HistoryHelper
5
+ # Builds a history object, separating and sorting data into time periods
6
+ include Parliament::NTriple::Utils
7
+
8
+ attr_writer :year_separator
9
+
10
+ # Returns year_separator variable (getter method)
11
+ #
12
+ # @return [Integer] Number of years used to divide up the timeline into time periods
13
+ def self.year_separator
14
+ @year_separator ||= 10
15
+ end
16
+
17
+ # Creates/sets an empty history object
18
+ #
19
+ # @return [Hash] Object with properties of start, current and years
20
+ def self.history
21
+ @history ||= {
22
+ start: nil,
23
+ current: [],
24
+ # Keys are the time periods
25
+ # Value is array of Grom::Nodes that have occured during this time period
26
+ years: {}
27
+ }
28
+ end
29
+
30
+ # Resets history
31
+ #
32
+ # @return [nil] Resets history to nil
33
+ def self.reset
34
+ @history = nil
35
+ end
36
+
37
+ # Adds data to history object, separating current Grom::Nodes from historic Grom::Nodes
38
+ # and setting start date of earliest Grom::Node
39
+ #
40
+ # @param data [Array] Array of Grom::Nodes
41
+ # @return [Hash] History object with Grom::Nodes divided into historic and current
42
+ def self.add(data)
43
+ return if data.nil? || data.empty?
44
+ # Set history if it has not already been set
45
+ history
46
+ data.each do |entry|
47
+ # Current
48
+ @history[:current] << entry if entry.try(:end_date).nil?
49
+
50
+ # Exit if there is no end date or if the end date is not a date
51
+ next if entry.try(:end_date).try(:year).try(:to_f).nil?
52
+
53
+ # e.g. If current year is 2017, end date is 2008 and year_separator is 10...
54
+ # year = ((2017-2008)/10).ceil) * 10 = 0
55
+ # But as it happened within the last 10 years, we want it to be placed in the 10 year time period, not 0
56
+ year = ((Time.now.year.to_f - entry.end_date.year.to_f) / year_separator).ceil * year_separator
57
+ year = year_separator if year == 0
58
+
59
+ @history[:years][year] = [] unless @history[:years][year]
60
+ @history[:years][year] << entry
61
+
62
+ if entry.respond_to?(:start_date)
63
+ @history[:start] = entry.start_date if @history[:start].nil? || @history[:start] > entry.start_date
64
+ end
65
+ end
66
+
67
+ # Sort current Grom::Nodes by start date
68
+ @history[:current].sort_by!(&:start_date).reverse!
69
+ sort_history
70
+ end
71
+
72
+ # Sorts Grom::Nodes first by end date, then by start date (if same end date)
73
+ #
74
+ # @return [Hash] History object with divided and sorted Grom::Nodes
75
+ def self.sort_history
76
+ @history[:years].keys.each do |year|
77
+ @history[:years][year] = Parliament::NTriple::Utils.multi_direction_sort(
78
+ {
79
+ list: @history[:years][year],
80
+ parameters: { end_date: :desc, start_date: :desc }
81
+ }
82
+ )
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -10,6 +10,7 @@ require_relative './helpers/v_card_helper'
10
10
  require_relative './helpers/grouping_helper'
11
11
  require_relative './helpers/role_grouping_helper'
12
12
  require_relative './helpers/business_item_grouping_helper'
13
+ require_relative './helpers/history_helper'
13
14
 
14
15
  require 'parliament/grom/decorator'
15
16
 
@@ -1,5 +1,5 @@
1
1
  module Parliament
2
2
  module Utils
3
- VERSION = '0.10.0'.freeze
3
+ VERSION = '0.10.1'.freeze
4
4
  end
5
5
  end
@@ -42,4 +42,5 @@ Gem::Specification.new do |spec|
42
42
  spec.add_development_dependency 'simplecov', '~> 0.12'
43
43
  spec.add_development_dependency 'sqlite3', '~> 1.3'
44
44
  spec.add_development_dependency 'webmock', '~> 2.3'
45
+ spec.add_development_dependency 'timecop'
45
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parliament-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rebecca Appleyard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parliament-ruby
@@ -290,6 +290,20 @@ dependencies:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
292
  version: '2.3'
293
+ - !ruby/object:Gem::Dependency
294
+ name: timecop
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
293
307
  description: Parliament Utils gem.
294
308
  email:
295
309
  - rklappleyard@gmail.com
@@ -336,6 +350,7 @@ files:
336
350
  - lib/parliament/utils/helpers/filter_helper.rb
337
351
  - lib/parliament/utils/helpers/flag_helper.rb
338
352
  - lib/parliament/utils/helpers/grouping_helper.rb
353
+ - lib/parliament/utils/helpers/history_helper.rb
339
354
  - lib/parliament/utils/helpers/houses_helper.rb
340
355
  - lib/parliament/utils/helpers/markdown_helper.rb
341
356
  - lib/parliament/utils/helpers/parliament_helper.rb