active_object 1.0.8 → 1.1.0

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: ca650a6d8bd2819442bd2fbd9b71a4af052911df
4
- data.tar.gz: 7addbb3a30efde0f8b7d8d14bb4b069aa7845e4c
3
+ metadata.gz: 41f1589ef378acdab8f63ff84e5a25af80acf4f6
4
+ data.tar.gz: 89f1a385c4773f14fce2bbd59505cb5ec57de97c
5
5
  SHA512:
6
- metadata.gz: f211ab12df50354085e3a0d6a39c20b33e5ce83dd05872c5710072f79eba7c3dcf14b0e8f551ea88dc981c881c4986dc2a25d4cc66e496336b82ff47f11e5031
7
- data.tar.gz: 336ba9b57620e9185ef0eaa7e41eadd8fd4d0e861be27c464b1943e2834306e4342ea269759b5d10f62f0b33660a6c1dc33fb5ed2fdd017ae42a53256b4cd42d
6
+ metadata.gz: 01614663b0ebd57e9750e18c3067d08115790e44fe5aa2e44075ecb1da156903a3a888dc3f6dd6734e3bdf926044b6f2dc9bc23341947c40af76f42c8a808fe4
7
+ data.tar.gz: 68872fc5a96cb9b4edb8131cc1ad1a1e9908dd640aeb687d8cf7f831200e8eeaa91900c22160b3d00303f937832d1fb4dd92946163b5cba3862a10f92c15288c
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/drexed/active_object.svg?branch=master)](https://travis-ci.org/drexed/active_object)
5
5
  [![Coverage Status](https://coveralls.io/repos/drexed/active_object/badge.png)](https://coveralls.io/r/drexed/active_object)
6
6
 
7
- ActiveObject is a collection of commonly used object helpers in a ruby based project. It currently includes extensions for: arrays, enumerables, hashes, integers, numerics, objects, strings, and time.
7
+ ActiveObject is a collection of commonly used object helpers in a ruby based project. It currently includes extensions for: arrays, enumerables, hashes, integers, numerics, objects, range, strings, and time.
8
8
 
9
9
  `Rails Safe` = methods extracted from rails but that do not override that rails method.
10
10
 
@@ -982,8 +982,35 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
982
982
  "example".try(:fake_method) #=> nil
983
983
  ```
984
984
 
985
+ ### Range
986
+
987
+ ####Include With Range:####
988
+ `include_with_range?` determines if a range includes another range. `Rails Safe`
989
+
990
+ ```ruby
991
+ (1..5).include?(1..5) # => true
992
+ (1..5).include?(2..3) # => true
993
+ (1..5).include?(2..6) # => false
994
+ ```
995
+
996
+ ####Overlaps:####
997
+ `overlaps?` determines if two ranges overlap each other. `Rails Safe`
998
+
999
+ ```ruby
1000
+ (1..5).overlaps?(4..6) # => true
1001
+ (1..5).overlaps?(7..9) # => false
1002
+ ```
1003
+
985
1004
  ### String
986
1005
 
1006
+ ####Any:####
1007
+ `any?` determines if a string includes a set of string(s).
1008
+
1009
+ ```ruby
1010
+ "example string".any?("foo") #=> false
1011
+ "example string".any?("foo", "string") #=> true
1012
+ ```
1013
+
987
1014
  ####At:####
988
1015
  `at` returns the characters at index position, matching string, or regex. `Rails Safe`
989
1016
 
@@ -5,5 +5,6 @@ require 'active_object/hash'
5
5
  require 'active_object/integer'
6
6
  require 'active_object/numeric'
7
7
  require 'active_object/object'
8
+ require 'active_object/range'
8
9
  require 'active_object/string'
9
10
  require 'active_object/time'
@@ -0,0 +1,20 @@
1
+ class Range
2
+
3
+ unless defined?(Rails)
4
+ def include_with_range?(value)
5
+ if value.is_a?(::Range)
6
+ operator = exclude_end? && !value.exclude_end? ? :< : :<=
7
+ include?(value.first) && value.last.send(operator, last)
8
+ else
9
+ include?(value)
10
+ end
11
+ end
12
+ end
13
+
14
+ unless defined?(Rails)
15
+ def overlaps?(other)
16
+ cover?(other.first) || other.cover?(first)
17
+ end
18
+ end
19
+
20
+ end
@@ -1,5 +1,16 @@
1
1
  class String
2
2
 
3
+ def any?(*keys)
4
+ included = false
5
+
6
+ keys.each do |key|
7
+ (included = true) if include?(key)
8
+ break if included
9
+ end
10
+
11
+ return(included)
12
+ end
13
+
3
14
  unless defined?(Rails)
4
15
  def at(position)
5
16
  self[position]
@@ -1,3 +1,3 @@
1
1
  module ActiveObject
2
- VERSION = "1.0.8"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -12,7 +12,7 @@ describe Hash do
12
12
  end
13
13
 
14
14
  it "to raise error" do
15
- expect { { foo: "bar", baz: "boz" }.assert_valid_keys(:foo) }.to raise_error
15
+ expect { { foo: "bar", baz: "boz" }.assert_valid_keys(:foo) }.to raise_error(ArgumentError)
16
16
  end
17
17
  end
18
18
 
@@ -420,10 +420,10 @@ describe Numeric do
420
420
  end
421
421
 
422
422
  it "to raise error" do
423
- expect { 1.to_byte }.to raise_error
424
- expect { 1.to_byte(:bad, :kilobyte) }.to raise_error
425
- expect { 1.to_byte(:kilobyte, :bad) }.to raise_error
426
- expect { 1.to_byte(:bad, :bad) }.to raise_error
423
+ expect { 1.to_byte }.to raise_error(ArgumentError)
424
+ expect { 1.to_byte(:bad, :kilobyte) }.to raise_error(ArgumentError)
425
+ expect { 1.to_byte(:kilobyte, :bad) }.to raise_error(ArgumentError)
426
+ expect { 1.to_byte(:bad, :bad) }.to raise_error(ArgumentError)
427
427
  end
428
428
  end
429
429
 
@@ -482,10 +482,10 @@ describe Numeric do
482
482
  end
483
483
 
484
484
  it "to raise error" do
485
- expect { 1.to_length }.to raise_error
486
- expect { 1.to_length(:bad, :meters) }.to raise_error
487
- expect { 1.to_length(:meters, :bad) }.to raise_error
488
- expect { 1.to_length(:bad, :bad) }.to raise_error
485
+ expect { 1.to_length }.to raise_error(ArgumentError)
486
+ expect { 1.to_length(:bad, :meters) }.to raise_error(ArgumentError)
487
+ expect { 1.to_length(:meters, :bad) }.to raise_error(ArgumentError)
488
+ expect { 1.to_length(:bad, :bad) }.to raise_error(ArgumentError)
489
489
  end
490
490
  end
491
491
 
@@ -522,10 +522,10 @@ describe Numeric do
522
522
  end
523
523
 
524
524
  it "to raise error" do
525
- expect { 1.to_mass }.to raise_error
526
- expect { 1.to_mass(:bad, :pound) }.to raise_error
527
- expect { 1.to_mass(:pound, :bad) }.to raise_error
528
- expect { 1.to_mass(:bad, :bad) }.to raise_error
525
+ expect { 1.to_mass }.to raise_error(ArgumentError)
526
+ expect { 1.to_mass(:bad, :pound) }.to raise_error(ArgumentError)
527
+ expect { 1.to_mass(:pound, :bad) }.to raise_error(ArgumentError)
528
+ expect { 1.to_mass(:bad, :bad) }.to raise_error(ArgumentError)
529
529
  end
530
530
  end
531
531
 
@@ -589,10 +589,10 @@ describe Numeric do
589
589
  end
590
590
 
591
591
  it "to raise error" do
592
- expect { 1.to_temperature }.to raise_error
593
- expect { 1.to_temperature(:bad, :kelvin) }.to raise_error
594
- expect { 1.to_temperature(:kelvin, :bad) }.to raise_error
595
- expect { 1.to_temperature(:bad, :bad) }.to raise_error
592
+ expect { 1.to_temperature }.to raise_error(ArgumentError)
593
+ expect { 1.to_temperature(:bad, :kelvin) }.to raise_error(ArgumentError)
594
+ expect { 1.to_temperature(:kelvin, :bad) }.to raise_error(ArgumentError)
595
+ expect { 1.to_temperature(:bad, :bad) }.to raise_error(ArgumentError)
596
596
  end
597
597
  end
598
598
 
@@ -618,10 +618,10 @@ describe Numeric do
618
618
  end
619
619
 
620
620
  it "to raise error" do
621
- expect { 1.to_time }.to raise_error
622
- expect { 1.to_time(:bad, :days) }.to raise_error
623
- expect { 1.to_time(:days, :bad) }.to raise_error
624
- expect { 1.to_time(:bad, :bad) }.to raise_error
621
+ expect { 1.to_time }.to raise_error(ArgumentError)
622
+ expect { 1.to_time(:bad, :days) }.to raise_error(ArgumentError)
623
+ expect { 1.to_time(:days, :bad) }.to raise_error(ArgumentError)
624
+ expect { 1.to_time(:bad, :bad) }.to raise_error(ArgumentError)
625
625
  end
626
626
  end
627
627
 
@@ -78,7 +78,7 @@ describe Object do
78
78
  end
79
79
 
80
80
  it "to raise error" do
81
- expect { "example".try!(:fake_method) }.to raise_error
81
+ expect { "example".try!(:fake_method) }.to raise_error(NoMethodError)
82
82
  end
83
83
  end
84
84
 
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Range do
4
+
5
+ describe "#include_with_range?" do
6
+ it "to be true" do
7
+ expect((1..5).include_with_range?(1..5)).to eq(true)
8
+ expect((1..5).include_with_range?(2..3)).to eq(true)
9
+ end
10
+
11
+ it "to be false" do
12
+ expect((1..5).include_with_range?(2..6)).to eq(false)
13
+ end
14
+ end
15
+
16
+ describe "#overlaps?" do
17
+ it "to be true" do
18
+ expect((1..5).overlaps?(4..6)).to eq(true)
19
+ end
20
+
21
+ it "to be false" do
22
+ expect((1..5).overlaps?(7..9)).to eq(false)
23
+ end
24
+ end
25
+
26
+ end
@@ -2,6 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe String do
4
4
 
5
+ describe "#any?" do
6
+ it "to be true" do
7
+ expect("example string".any?("example")).to eq(true)
8
+ expect("example string".any?("foo", "string")).to eq(true)
9
+ end
10
+
11
+ it "to be false" do
12
+ expect("example string".any?("foo")).to eq(false)
13
+ expect("example string".any?("foo", "bar")).to eq(false)
14
+ end
15
+ end
16
+
5
17
  describe "#at" do
6
18
  it "to be e" do
7
19
  expect("example".at(0)).to eq("e")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/active_object/integer.rb
90
90
  - lib/active_object/numeric.rb
91
91
  - lib/active_object/object.rb
92
+ - lib/active_object/range.rb
92
93
  - lib/active_object/string.rb
93
94
  - lib/active_object/time.rb
94
95
  - lib/active_object/version.rb
@@ -98,6 +99,7 @@ files:
98
99
  - spec/lib/integer_spec.rb
99
100
  - spec/lib/numeric_spec.rb
100
101
  - spec/lib/object_spec.rb
102
+ - spec/lib/range_spec.rb
101
103
  - spec/lib/string_spec.rb
102
104
  - spec/lib/time_spec.rb
103
105
  - spec/spec_helper.rb
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  version: '0'
122
124
  requirements: []
123
125
  rubyforge_project:
124
- rubygems_version: 2.4.6
126
+ rubygems_version: 2.4.8
125
127
  signing_key:
126
128
  specification_version: 4
127
129
  summary: Commonly used ruby object helpers.
@@ -132,6 +134,7 @@ test_files:
132
134
  - spec/lib/integer_spec.rb
133
135
  - spec/lib/numeric_spec.rb
134
136
  - spec/lib/object_spec.rb
137
+ - spec/lib/range_spec.rb
135
138
  - spec/lib/string_spec.rb
136
139
  - spec/lib/time_spec.rb
137
140
  - spec/spec_helper.rb