dm_ruby_extensions 1.0.8 → 1.0.9

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: ef89479e99db1c9f1aec46b1e5cd35b0a32b66bc
4
- data.tar.gz: 796817a8a3db9ab1778400f2d8f91455f034f2e4
3
+ metadata.gz: faf35d14eb0e9a4fd037b1e3b3aed616141a0cb4
4
+ data.tar.gz: 3419c2d7b07edcc1dcf0c5c5a3bcd0abb1d6a4c7
5
5
  SHA512:
6
- metadata.gz: 97d7c140af39371f7cd050f8cbe70690916eb9d6f6c0694e23fd5855590fa3031cda396d3afb6fbb995dbe503b2ef48f8791b6a1703d733f26e919b198a35d64
7
- data.tar.gz: '025885950263f3cb3601b194190a3c2556acafe262d67e914d1e5300bdb6ad2276288793d2aaa2aa12356c0fbf5afebdbd83f6d5101be4e1183c8a31a15af509'
6
+ metadata.gz: ff6026e4c21a2adc2238854c7ac1623bd6d8931ff9ecbab07bb7b4b535b28885bca80f568b1d2445f313c3ec29a3a46cce147f85143db802b274f0b02eddd54c
7
+ data.tar.gz: b2ff730e615af076f516718e68ad5f6f2a08467f327146c7b446c6e76c99be09b7652c79162c13df645463d735bcddf070727d115aa6f71ca3984beca6f6f230
data/Gemfile CHANGED
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'rake'
6
- gem 'byebug'
6
+ gem 'pry-byebug'
7
7
  gem 'rspec'
@@ -35,7 +35,7 @@ class Array
35
35
 
36
36
  # given an array of css classes/styles, join them into one string.
37
37
  # only join non-nil/non-empty strings, and return nil if the result
38
- # is an empty string (rails tag methods will not include the
38
+ # is an empty string (rails tag methods will not include the
39
39
  # attribute if it is nil, which is desirable for cleaner html)
40
40
  #------------------------------------------------------------------------------
41
41
  def css_join(delimiter = '')
@@ -43,4 +43,3 @@ class Array
43
43
  str == '' ? nil : str
44
44
  end
45
45
  end
46
-
@@ -13,4 +13,4 @@ class Integer
13
13
  (self > 0) ? true : false
14
14
  end
15
15
 
16
- end
16
+ end
@@ -1,8 +1,6 @@
1
1
  class Numeric
2
-
3
2
  #------------------------------------------------------------------------------
4
3
  def percent_of(n, precision = 0)
5
4
  n == 0 ? 0 : (self.to_f / n.to_f * 100.0).round(precision)
6
5
  end
7
-
8
- end
6
+ end
@@ -7,7 +7,7 @@ class String #:nodoc:
7
7
  def to_s_default(default_str = 'n/a')
8
8
  (empty? || strip.empty?) ? default_str : self.to_s
9
9
  end
10
-
10
+
11
11
  #------------------------------------------------------------------------------
12
12
  def as_boolean
13
13
  (self == 'true' || self == 'yes' || self == '1') ? true : false
@@ -24,15 +24,15 @@ class String #:nodoc:
24
24
  # Adds SQL wildcard cahracters to begin/end of string for use in LIKE statements
25
25
  #------------------------------------------------------------------------------
26
26
  def sql_wildcard
27
- "%#{self}%"
27
+ "%#{self}%"
28
28
  end
29
-
29
+
30
30
  # Replace non-alphanumbic character
31
31
  #------------------------------------------------------------------------------
32
32
  def replace_non_alphanumeric(replacement = '')
33
33
  self.gsub /[^\w\.\-]/, replacement
34
34
  end
35
-
35
+
36
36
  # Santize the string
37
37
  # Note: File.basename doesn't work right with Windows paths on Unix
38
38
  #------------------------------------------------------------------------------
@@ -40,13 +40,13 @@ class String #:nodoc:
40
40
  name = self.strip
41
41
  #--- get only the filename, not the whole path
42
42
  name.gsub! /^.*(\\|\/)/, ''
43
-
43
+
44
44
  #--- Finally, replace all non alphanumeric, underscore or periods with underscore
45
45
  name.gsub! /[^\w\.\-]/, '_'
46
46
  return name
47
47
  end
48
48
 
49
- # if a relative url path is given, then expand it by prepending the supplied
49
+ # if a relative url path is given, then expand it by prepending the supplied
50
50
  # path.
51
51
  #------------------------------------------------------------------------------
52
52
  def expand_url(path = '')
@@ -70,7 +70,7 @@ class String #:nodoc:
70
70
  #------------------------------------------------------------------------------
71
71
  def smart_titlecase
72
72
  small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs. von)
73
-
73
+
74
74
  x = split(" ").map do |word|
75
75
  # note: word could contain non-word characters!
76
76
  # downcase all small_words, capitalize the rest
@@ -83,7 +83,7 @@ class String #:nodoc:
83
83
  # small words after colons are capitalized
84
84
  x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " }
85
85
  end
86
-
86
+
87
87
  #------------------------------------------------------------------------------
88
88
  def smart_capitalize
89
89
  # ignore any leading crazy characters and capitalize the first real character
@@ -95,7 +95,7 @@ class String #:nodoc:
95
95
  end
96
96
  self
97
97
  end
98
-
98
+
99
99
  #------------------------------------------------------------------------------
100
100
  def smart_capitalize!
101
101
  replace(smart_capitalize)
@@ -113,10 +113,10 @@ class String #:nodoc:
113
113
  end
114
114
  a = self.split(/\s/) # or /[ ]+/ to only split on spaces
115
115
  n = opts[:words]
116
- a[0...n].join(' ') + (a.size > n ? '...' : '')
116
+ a[0...n].join(' ') + (a.size > n ? '...' : '')
117
117
  end
118
118
  #------------------------------------------------------------------------------
119
-
119
+
120
120
  # http://github.com/tenderlove/namecase
121
121
  # NameCase is a Ruby implementation of Lingua::EN::NameCase, a library for
122
122
  # converting strings/names to be properly cased. This is good for converting
@@ -182,12 +182,11 @@ class String #:nodoc:
182
182
 
183
183
  localstring
184
184
  end
185
-
185
+
186
186
  # Modifies _str_ in place and properly namecases the string.
187
187
  #------------------------------------------------------------------------------
188
188
  def name_case!
189
189
  self.gsub!(self, self.name_case)
190
190
  end
191
-
192
- end
193
191
 
192
+ end
@@ -1,3 +1,3 @@
1
1
  module DmRubyExtensions
2
- VERSION = '1.0.8'
2
+ VERSION = '1.0.9'
3
3
  end
@@ -4,11 +4,11 @@ require 'dm_ruby_extensions'
4
4
  describe Date do
5
5
 
6
6
  describe 'to_age' do
7
- it 'return number of years since now', pending: 'not sure how to test' do
8
- expect(Date.new(1967, 1, 23).to_age).to eq 0
7
+ it 'return number of years since now' do
8
+ expect(Date.new(Time.now.year - 50, Time.now.month, Time.now.day).to_age).to eq 50
9
9
  end
10
10
  end
11
-
11
+
12
12
  describe 'localize' do
13
13
  it 'localize the date based on the format' do
14
14
  I18n.enforce_available_locales = false
@@ -19,11 +19,11 @@ describe Date do
19
19
  expect(date.localize('%b %Y')).to eq 'Nov 2012'
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe 'to_index' do
24
24
  it 'creates unique sortable index for a date' do
25
25
  date = Date.new(2012, 11, 23)
26
26
  expect(date.to_index).to eq 12328
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -4,11 +4,11 @@ require 'dm_ruby_extensions'
4
4
  describe DateTime do
5
5
 
6
6
  describe 'to_age' do
7
- it 'return number of years since now', pending: 'not sure how to test' do
8
- expect(DateTime.new(1967, 1, 23).to_age).to eq 0
7
+ it 'return number of years since now' do
8
+ expect(DateTime.new(Time.now.year - 50, Time.now.month, Time.now.day).to_age).to eq 50
9
9
  end
10
10
  end
11
-
11
+
12
12
  describe 'localize' do
13
13
  it 'localize the date based on the format' do
14
14
  I18n.enforce_available_locales = false
@@ -19,11 +19,11 @@ describe DateTime do
19
19
  expect(date.localize('%b %Y')).to eq 'Nov 2012'
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe 'to_index' do
24
24
  it 'creates unique sortable index for a date' do
25
25
  date = Date.new(2012, 11, 23)
26
26
  expect(date.to_index).to eq 12328
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
  require 'dm_ruby_extensions'
3
3
 
4
4
  describe Integer do
5
-
6
5
  describe 'factorial' do
7
6
  #------------------------------------------------------------------------------
8
7
  it 'return the factorial of the number' do
@@ -16,5 +15,4 @@ describe Integer do
16
15
  specify { expect(0.as_boolean).to be_falsey }
17
16
  specify { expect(20.as_boolean).to be_truthy }
18
17
  end
19
-
20
- end
18
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'pry-byebug'
1
2
  # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
3
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
4
  # The generated `.rspec` file contains `--require spec_helper` which will cause this
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm_ruby_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Walker