has_accounts 2.1.0 → 3.0.0.beta0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 403d094803675510f38b33a494676ed9f70050b5
4
- data.tar.gz: 0a39e6943b89d82857bf0386c9342c97c395a355
3
+ metadata.gz: 7536557b72ba28c4867b5e4397b03f8a06d5dfb3
4
+ data.tar.gz: b73be36ba1905821003318b7a836700c5343538a
5
5
  SHA512:
6
- metadata.gz: 06fad61f4d896918f0bb135062f4a7f29504699e2f1d7544f6e711d25d16034bfa85bf03218b90ed2699453026e6d2ef31543ee7ba6ab18a7ee9181dd4e98589
7
- data.tar.gz: f9a03bb6639014b0de59b8a98ba80ef84d1fead4b9f6f922772fecc9d1df65e894d1b14f4426882be1f9abce270e45cfe8754d2248f824baf9e6009b3cf99a91
6
+ metadata.gz: 56d71c0b21006327dcbf25351c3c7ae7d11fba23afaa254138ef45f0a3b064c4d07b9bd33772bb7fc7054e273175afbc013e24e3a69a9dac1baffbf27fd82a9b
7
+ data.tar.gz: 3379c6d6c3f491728d922247d999f8576366b0295d45cef037db6ff6a6d06c42257e979e95178bda3ef9180e081068c477871d4a1a89b314342b2b03a6713361
@@ -75,6 +75,61 @@ class Booking < ActiveRecord::Base
75
75
  end
76
76
  }
77
77
 
78
+ # Scope filter for date range
79
+ scope :by_date_period, lambda {|date_from, date_to|
80
+ if date_from.present? && date_to.present?
81
+ where(:value_date => date_from..date_to)
82
+ elsif date_from.present?
83
+ where('value_date >= ?', date_from)
84
+ elsif date_to.present?
85
+ where('value_date <= ?', date_to)
86
+ end
87
+ }
88
+
89
+ # Scope for date filter
90
+ #
91
+ # @param from [Date]
92
+ # @param to [Date]
93
+ scope :by_date, lambda {|*args|
94
+ dates = args.map do |date|
95
+ begin
96
+ date.to_date
97
+ rescue
98
+ nil
99
+ end
100
+ end
101
+
102
+ if dates.count == 0
103
+ scoped
104
+ elsif dates.count == 1
105
+ where(:value_date => dates[0])
106
+ elsif dates.count == 2
107
+ by_date_period(dates[0], dates[1])
108
+ end
109
+ }
110
+
111
+ # Scope for amount range filter
112
+ scope :by_amount_range, lambda {|amount_from, amount_to|
113
+ if amount_from.present? && amount_to.present?
114
+ where(:amount => amount_from..amount_to)
115
+ elsif amount_from.present?
116
+ where('amount >= ?', amount_from)
117
+ elsif amount_to.present?
118
+ where('amount <= ?', amount_to)
119
+ end
120
+ }
121
+
122
+ # Scope for amount filter
123
+ scope :by_amount, lambda {|*args|
124
+ if args.count == 0
125
+ scoped
126
+ elsif args.count == 1
127
+ where(:amount => args[0])
128
+ elsif args.count == 2
129
+ by_amount_range(args[0], args[1])
130
+ end
131
+ }
132
+
78
133
  # Scope for all accounts assigned to account
79
134
  #
80
135
  # @param account_id [Integer]
@@ -1,3 +1,3 @@
1
1
  module HasAccounts
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0.beta0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0.beta0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hürlimann (CyT)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-27 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -84,9 +84,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - ">"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.3.1
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 2.2.2
@@ -94,3 +94,4 @@ signing_key:
94
94
  specification_version: 4
95
95
  summary: HasAccounts provides models for financial accounting.
96
96
  test_files: []
97
+ has_rdoc: