osm 1.2.15 → 1.2.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjY5Mjk4ZWNkMTdiOTYwNjEyNjMzZDE5ZDJlNDZkMDRlNDhlNjViZA==
4
+ ODIwM2UyMGRkZWZiZmMxN2Y5M2VhODlkZDgyZDhjY2Y2YzRhYjYyZQ==
5
5
  data.tar.gz: !binary |-
6
- YzkwMDhiNTljM2M5MTk0M2Y0MTUyN2MyYmVmNThlN2JlN2IwNjcxOQ==
6
+ ZmQ1OWJlOWUyMDUzNWFiMzk5MGJjYmYwMzAxOWNjMWU3ZTdiMTRiOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWRmZGI4YzdhOWVjNTk5NTYwNmM5OGQxMmJlYzNmYWQ4ZTcyNWE2ZDZlOTRj
10
- NTA0MTJmYmQyZDA5MjVhNGJmYmE2YzZhNjZlZDE4MGRjY2U2YjA5ZTEyMGYw
11
- OTc5ZDJjYmJhMjQ0NTRjMjNmMDM3Y2E0MWQyZmFjODY1ODUwM2Y=
9
+ NGUxNWIzNmE4MjlkMWQ1OTVhOTY2YTU3Y2VkMWZkYzZiMjFmZjk5Yzc1M2Qx
10
+ ZmRkZjU5YjA3MjNjYTQ3ZTFiMmEzYzkwOWRiYTc3YzhjNmRiOGE1YWQyZDc0
11
+ NDY3MWZkOTUwZjkwNTgyODk4MDY5Y2U3YzAzNGM5N2UwZDY5NDM=
12
12
  data.tar.gz: !binary |-
13
- OGYyMzY1OWU5NDMzNzlmNTk0Mjk2Yzg0YjAwZjIyYjY0MWU1MWFkZGE3ZWE2
14
- MjhhNGM1MmZmZGFmZWE4NDU4ZTc0MDk1MTBkYzlmNGIyMGU1MTliZTc1ZTBh
15
- NTk4NjE3NmVhY2Y1ZjY5Mzg3MGM2OWNhMDQzYzI4YzE4YjA2OGQ=
13
+ ZjE4OWI0YzNjZTliMTc2NzAwN2Y4N2JmOGQ4ZGNmYjA2OTJhMWJkMGNlZWU5
14
+ OTYxNjVhYTE5ZThjYjJhYWVmNjlmMWI1ZWQ3Yjg5ZWM5ZmQ0MGFkOTQ4ZTA1
15
+ YjE0NDlkOTdiYmY2MzhhNTYwZDRjMTZhZjU4MjZmYTJiYmYwOTY=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## Version 1.2.16
2
+
3
+ * Osm::Section gains instance methods:
4
+ * bronze?
5
+ * silver?
6
+ * gold?
7
+ * gold_plus?
8
+ * subscription_at_least?(level)
9
+ * Osm::SUBSCRIPTION_LEVEL_NAMES is now a Hash not an Array
10
+
1
11
  ## Version 1.2.15
2
12
 
3
13
  * Add support for census and giftaid link generation for members
data/lib/osm.rb CHANGED
@@ -36,7 +36,18 @@ module Osm
36
36
  OSM_TIME_REGEX = /\A(?:[0-1][0-9]|2[0-3]):[0-5][0-9]\Z/
37
37
  OSM_DATE_REGEX_UNANCHORED = /(?:[1-9]\d{3}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1]))|(?:(?:0?[1-9]|[1-2][0-9]|3[0-1])\/(?:0?[1-9]|1[0-2])\/(?:\d{2}|[1-9]\d{3}))/
38
38
  OSM_DATE_REGEX = /\A#{Osm::OSM_DATE_REGEX_UNANCHORED.to_s}\Z/
39
- SUBSCRIPTION_LEVEL_NAMES = ['Unknown', 'Bronze', 'Silver', 'Gold', 'Gold+']
39
+ subscription_level_names = {
40
+ 1 => 'Bronze',
41
+ :bronze => 'Bronze',
42
+ 2 => 'Silver',
43
+ :silver => 'Silver',
44
+ 3 => 'Gold',
45
+ :gold => 'Gold',
46
+ 4 => 'Gold+',
47
+ :gold_plus => 'Gold+',
48
+ }
49
+ subscription_level_names.default = 'Unknown'
50
+ SUBSCRIPTION_LEVEL_NAMES = subscription_level_names
40
51
  SUBSCRIPTION_LEVELS = [nil, :bronze, :silver, :gold, :gold_plus]
41
52
  end
42
53
 
data/lib/osm/model.rb CHANGED
@@ -209,23 +209,8 @@ module Osm
209
209
  # @raise [Osm::Forbidden] If the Section does not have the required OSM Subscription (or higher)
210
210
  def self.require_subscription(api, level, section, options={})
211
211
  section = Osm::Section.get(api, section, options) unless section.is_a?(Osm::Section)
212
- if level.is_a?(Symbol) # Convert to Fixnum
213
- case level
214
- when :bronze
215
- level = 1
216
- when :silver
217
- level = 2
218
- when :gold
219
- level = 3
220
- when :gold_plus
221
- level = 4
222
- else
223
- level = 0
224
- end
225
- end
226
- if section.nil? || section.subscription_level < level
227
- level_name = Osm::SUBSCRIPTION_LEVEL_NAMES[level] || level
228
- raise Osm::Forbidden, "Insufficent OSM subscription level (#{level_name} required for #{section.name})."
212
+ if section.nil? || !section.subscription_at_least?(level)
213
+ raise Osm::Forbidden, "Insufficent OSM subscription level (#{Osm::SUBSCRIPTION_LEVEL_NAMES[level]} required for #{section.name})."
229
214
  end
230
215
  end
231
216
 
data/lib/osm/section.rb CHANGED
@@ -376,6 +376,47 @@ module Osm
376
376
  Osm::SUBSCRIPTION_LEVEL_NAMES[subscription_level]
377
377
  end
378
378
 
379
+ # Check if the section has a subscription of a given level (or higher)
380
+ # @param level [Fixnum, Symbol] the subscription level required
381
+ # @return [Boolean] Whether the section has a subscription of level (or higher)
382
+ def subscription_at_least?(level)
383
+ if level.is_a?(Symbol) # Convert to Fixnum
384
+ case level
385
+ when :bronze
386
+ level = 1
387
+ when :silver
388
+ level = 2
389
+ when :gold
390
+ level = 3
391
+ when :gold_plus
392
+ level = 4
393
+ else
394
+ level = 0
395
+ end
396
+ end
397
+
398
+ return subscription_level >= level
399
+ end
400
+
401
+ # @!method bronze?
402
+ # Check if this has a Bronze level subscription
403
+ # @return (Boolean)
404
+ # @!method silver?
405
+ # Check if this has a Silver level subscription
406
+ # @return (Boolean)
407
+ # @!method gold?
408
+ # Check if this has a Gold level subscription
409
+ # @return (Boolean)
410
+ # @!method gold_plus?
411
+ # Check if this has a Gold+ level subscription
412
+ # @return (Boolean)
413
+ Osm::SUBSCRIPTION_LEVELS[1..-1].each_with_index do |attribute, index|
414
+ define_method "#{attribute}?" do
415
+ subscription_level == (index + 1)
416
+ end
417
+ end
418
+
419
+
379
420
  # Compare Section based on group_name type (age order), then name
380
421
  def <=>(another)
381
422
  result = self.group_name <=> another.try(:group_name)
@@ -295,6 +295,114 @@ describe "Section" do
295
295
  end
296
296
  end
297
297
 
298
+ describe "Corretly works out the subscription level" do
299
+
300
+ it "Bronze" do
301
+ section = Osm::Section.new(subscription_level: 1)
302
+ section.bronze?.should == true
303
+ section.silver?.should == false
304
+ section.gold?.should == false
305
+ section.gold_plus?.should == false
306
+ end
307
+
308
+ it "Silver" do
309
+ section = Osm::Section.new(subscription_level: 2)
310
+ section.bronze?.should == false
311
+ section.silver?.should == true
312
+ section.gold?.should == false
313
+ section.gold_plus?.should == false
314
+ end
315
+
316
+ it "Gold" do
317
+ section = Osm::Section.new(subscription_level: 3)
318
+ section.bronze?.should == false
319
+ section.silver?.should == false
320
+ section.gold?.should == true
321
+ section.gold_plus?.should == false
322
+ end
323
+
324
+ it "Gold+" do
325
+ section = Osm::Section.new(subscription_level: 4)
326
+ section.bronze?.should == false
327
+ section.silver?.should == false
328
+ section.gold?.should == false
329
+ section.gold_plus?.should == true
330
+ end
331
+
332
+ it "Unknown" do
333
+ section = Osm::Section.new(subscription_level: 0)
334
+ section.bronze?.should == false
335
+ section.silver?.should == false
336
+ section.gold?.should == false
337
+ section.gold_plus?.should == false
338
+ end
339
+
340
+ end # describe
341
+
342
+ describe "Correctly works out if a section has a subscription of at least" do
343
+
344
+ it "Bronze" do
345
+ section = Osm::Section.new(subscription_level: 1)
346
+ section.subscription_at_least?(:bronze).should == true
347
+ section.subscription_at_least?(:silver).should == false
348
+ section.subscription_at_least?(:gold).should == false
349
+ section.subscription_at_least?(:gold_plus).should == false
350
+ section.subscription_at_least?(1).should == true
351
+ section.subscription_at_least?(2).should == false
352
+ section.subscription_at_least?(3).should == false
353
+ section.subscription_at_least?(4).should == false
354
+ end
355
+
356
+ it "Silver" do
357
+ section = Osm::Section.new(subscription_level: 2)
358
+ section.subscription_at_least?(:bronze).should == true
359
+ section.subscription_at_least?(:silver).should == true
360
+ section.subscription_at_least?(:gold).should == false
361
+ section.subscription_at_least?(:gold_plus).should == false
362
+ section.subscription_at_least?(1).should == true
363
+ section.subscription_at_least?(2).should == true
364
+ section.subscription_at_least?(3).should == false
365
+ section.subscription_at_least?(4).should == false
366
+ end
367
+
368
+ it "Gold" do
369
+ section = Osm::Section.new(subscription_level: 3)
370
+ section.subscription_at_least?(:bronze).should == true
371
+ section.subscription_at_least?(:silver).should == true
372
+ section.subscription_at_least?(:gold).should == true
373
+ section.subscription_at_least?(:gold_plus).should == false
374
+ section.subscription_at_least?(1).should == true
375
+ section.subscription_at_least?(2).should == true
376
+ section.subscription_at_least?(3).should == true
377
+ section.subscription_at_least?(4).should == false
378
+ end
379
+
380
+ it "Gold+" do
381
+ section = Osm::Section.new(subscription_level: 4)
382
+ section.subscription_at_least?(:bronze).should == true
383
+ section.subscription_at_least?(:silver).should == true
384
+ section.subscription_at_least?(:gold).should == true
385
+ section.subscription_at_least?(:gold_plus).should == true
386
+ section.subscription_at_least?(1).should == true
387
+ section.subscription_at_least?(2).should == true
388
+ section.subscription_at_least?(3).should == true
389
+ section.subscription_at_least?(4).should == true
390
+ end
391
+
392
+ it "Unknown" do
393
+ section = Osm::Section.new(subscription_level: 0)
394
+ section.subscription_at_least?(:bronze).should == false
395
+ section.subscription_at_least?(:silver).should == false
396
+ section.subscription_at_least?(:gold).should == false
397
+ section.subscription_at_least?(:gold_plus).should == false
398
+ section.subscription_at_least?(1).should == false
399
+ section.subscription_at_least?(2).should == false
400
+ section.subscription_at_least?(3).should == false
401
+ section.subscription_at_least?(4).should == false
402
+ end
403
+
404
+ end # describe
405
+
298
406
  end
299
407
 
300
408
 
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Osm
2
- VERSION = "1.2.15"
2
+ VERSION = "1.2.16"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.15
4
+ version: 1.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gauld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport