corelib 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/corelib/array/helpers.rb +64 -16
- data/lib/corelib/string/core.rb +37 -1
- data/lib/corelib/version.rb +1 -1
- data/spec/array/helpers_spec.rb +19 -0
- data/spec/object/core_spec.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec4f66acccd5ce6fe48870677dee180718b2d17b
|
4
|
+
data.tar.gz: 3c5052450fcf5c47ff0fb148a989a213587d7aec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43d0708b128dd8b37a6088b1788a389205cd519a4f1f5a6eef3b0bbd9cd3ae664a472a0afd814242b24d18729e747f90364090f7ac4d68eb95e82e7138b90307
|
7
|
+
data.tar.gz: de87d535265d31237d724a8ff1b4f6afc313315fadebd7b6510aed6d1b6e5dfb03bda554a18b68473d802c14b8bc0a3c8ca33353d3a3777f7e909622a3060fc5
|
@@ -2,16 +2,64 @@ class Array
|
|
2
2
|
|
3
3
|
def options_label_for(value)
|
4
4
|
sub = self.find {|each| each[1] == value}
|
5
|
-
|
6
|
-
sub[0]
|
5
|
+
sub.nil? ? nil : sub[0]
|
7
6
|
end
|
8
7
|
|
9
|
-
def self.
|
8
|
+
def self.time_clock_type_options(options={})
|
9
|
+
exemplify = options.fetch(:exemplify, true)
|
10
|
+
id = options.fetch(:start_id, 1)
|
11
|
+
return [["12-Hour Clock", id], ["24-Hour Clock", id+1]] if !exemplify
|
12
|
+
|
13
|
+
t = Time.now
|
14
|
+
s = options.fetch(:separater, " - ")
|
15
|
+
h = options.fetch(:day, t.strftime("%l"))
|
16
|
+
m = options.fetch(:month, t.strftime("%m"))
|
17
|
+
ap =options.fetch(:am_pm, t.strftime("%P"))
|
18
|
+
hm = options.fetch(:day24, t.strftime("%H"))
|
19
|
+
[["12-Hour Clock#{s}(#{h}:#{m}#{ap})", id], ["24-Hour Clock#{s}(#{hm}:#{m})", id+1]]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.date_format_options(options={})
|
23
|
+
exemplify = options.fetch(:exemplify, true)
|
24
|
+
exemplify ? date_format_options_exemplified_raw(options) : date_format_options_raw(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.date_format_options_raw(options={})
|
28
|
+
id = options.fetch(:start_id, 1)
|
29
|
+
[["MM/DD/YYYY", id], ["MM-DD-YYYY", id+1], ["DD/MM/YYYY", id+2], ["DD-MM-YYYY", id+3], ["YYYY/MM/DD", id+4], ["YYYY-MM-DD", id+5], ["DD.MM.YYYY", id+6], ["YYYY.MM.DD", id+7]]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.date_format_options_exemplified_raw(options={})
|
33
|
+
id = options.fetch(:start_id, 1)
|
34
|
+
t = Time.now
|
35
|
+
s = options.fetch(:separater, " - ")
|
36
|
+
d = options.fetch(:day, t.strftime("%d"))
|
37
|
+
m = options.fetch(:month, t.strftime("%m"))
|
38
|
+
y = options.fetch(:year, t.year)
|
39
|
+
[["MM/DD/YYYY#{s}(#{m}/#{d}/#{y})", id], ["MM-DD-YYYY#{s}(#{m}-#{d}-#{y})", id+1], ["DD/MM/YYYY#{s}(#{d}/#{m}/#{y})", id+2], ["DD-MM-YYYY#{s}(#{d}-#{m}-#{y})", id+3],
|
40
|
+
["YYYY/MM/DD#{s}(#{y}/#{m}/#{d})", id+4], ["YYYY-MM-DD#{s}(#{y}-#{m}-#{d})", id+5], ["DD.MM.YYYY#{s}(#{d}.#{m}.#{y})", id+6], ["YYYY.MM.DD#{s}(#{y}.#{m}.#{d})", id+7]]
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.month_options(options={})
|
10
44
|
abbrev = options.fetch(:abbrev, false)
|
11
|
-
|
45
|
+
list = abbrev ? month_options_abbrev_raw : month_options_raw
|
46
|
+
list.format_options_list(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.month_options_raw(start=1)
|
50
|
+
[["January", start], ["February", start + 1], ["March", start + 2], ["April", start + 3], ["May", start + 4], ["June", start + 5],
|
51
|
+
["July", start + 6], ["August", start + 7], ["September", start + 8], ["October", start + 9], ["November", start + 10], ["December", start + 11]]
|
52
|
+
end
|
12
53
|
|
54
|
+
def self.month_options_abbrev_raw(start=1)
|
55
|
+
[["Jan", start], ["Feb", start + 1], ["Mar", start + 2], ["Apr", start + 3], ["May", start + 4], ["Jun", start + 5],
|
56
|
+
["Jul", start + 6], ["Aug", start + 7], ["Sep", start + 8], ["Oct", start + 9], ["Nov", start + 10], ["Dec", start + 11]]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.us_state_options(options={})
|
60
|
+
abbrev = options.fetch(:abbrev, false)
|
13
61
|
list = abbrev ? us_state_options_abbrev_raw : us_state_options_raw
|
14
|
-
list.
|
62
|
+
list.format_options_list(options)
|
15
63
|
end
|
16
64
|
|
17
65
|
def self.us_state_options_raw
|
@@ -38,24 +86,24 @@ class Array
|
|
38
86
|
['WV', 'WV'], ['WI', 'WI'], ['WY', 'WY'],]
|
39
87
|
end
|
40
88
|
|
41
|
-
def
|
89
|
+
def format_options_list(options={})
|
90
|
+
insert_options_label_blank(options)
|
91
|
+
change_options_label_case(options) if options[:format] #Change case if :format is set, otherwise use default case
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def insert_options_label_blank(options)
|
42
98
|
add_blank = options.fetch(:blank, "true")
|
43
99
|
blank_value = options.fetch(:blank_value, 0)
|
44
100
|
blank_label = options.fetch(:blank_label, "")
|
45
101
|
blank_position = options.fetch(:blank_position, 0)
|
46
102
|
self.insert(blank_position, [blank_label, blank_value]) if add_blank
|
47
|
-
change_us_state_list_label_case(options)
|
48
|
-
self
|
49
103
|
end
|
50
104
|
|
51
|
-
|
52
|
-
|
53
|
-
def change_us_state_list_label_case(options)
|
54
|
-
abbrev = options.fetch(:abbrev)
|
55
|
-
label_format = abbrev ? options.fetch(:format, "Up") : options.fetch(:format, "Cap")
|
56
|
-
return self if (label_format == "Up") and abbrev
|
57
|
-
return self if (label_format == "Cap") and !abbrev
|
58
|
-
|
105
|
+
def change_options_label_case(options)
|
106
|
+
label_format = options.fetch(:format)
|
59
107
|
self.each {|opt| opt[0].upcase!} if label_format == "Up"
|
60
108
|
self.each {|opt| opt[0].capitalize!} if label_format == "Cap"
|
61
109
|
self.each {|opt| opt[0].downcase!} if label_format == "Down"
|
data/lib/corelib/string/core.rb
CHANGED
@@ -1,11 +1,47 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
+
#TODO - Needs Tests
|
4
|
+
def last
|
5
|
+
return nil if self.empty?
|
6
|
+
self[-1,1]
|
7
|
+
end
|
8
|
+
|
9
|
+
#TODO - Needs Tests
|
10
|
+
def first
|
11
|
+
return nil if self.empty?
|
12
|
+
self[0,1]
|
13
|
+
end
|
14
|
+
|
15
|
+
#TODO - Needs Tests
|
16
|
+
# Combines two strings together with a separator.
|
17
|
+
def combine(str, options={})
|
18
|
+
strip = options.fetch(:strip, true)
|
19
|
+
return compact ? self.strip : self.dup if str.nil? or str.empty?
|
20
|
+
return compact ? str.strip : str.dup if self.empty?
|
21
|
+
separator = options.fetch(:separator, " ")
|
22
|
+
|
23
|
+
if strip
|
24
|
+
pre = self.strip
|
25
|
+
post = str.strip
|
26
|
+
else
|
27
|
+
pre = self.dup
|
28
|
+
post = str.dup
|
29
|
+
end
|
30
|
+
|
31
|
+
return pre + post if separator.empty?
|
32
|
+
|
33
|
+
# TODO - Support other separators other than spaces. For instance if someone wanted to join with a comma
|
34
|
+
# and pre ended with a comma, we could have an option to disallow repeating
|
35
|
+
pre + separator + post
|
36
|
+
|
37
|
+
end
|
38
|
+
|
3
39
|
#Does the same thing as String#contact, but allows a separator to be inserted between the
|
4
40
|
#two strings.
|
5
41
|
def concat_with(str, separator="")
|
6
42
|
return self if str.nil? or str.empty?
|
7
43
|
return self.concat(str) if self.empty?
|
8
|
-
self.concat(separator)
|
44
|
+
self.concat(separator) unless separator.empty?
|
9
45
|
self.concat(str)
|
10
46
|
end
|
11
47
|
|
data/lib/corelib/version.rb
CHANGED
data/spec/array/helpers_spec.rb
CHANGED
@@ -20,6 +20,25 @@ describe Array do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
describe "#month_options" do
|
24
|
+
it "has the right number of entries" do
|
25
|
+
Array.month_options.size.should == 13
|
26
|
+
Array.month_options(:blank => false).size.should == 12
|
27
|
+
end
|
28
|
+
it "returns the correct list" do
|
29
|
+
Array.month_options[1][0].should == "January"
|
30
|
+
Array.month_options(:abbrev => true)[1][0].should == "Jan"
|
31
|
+
end
|
32
|
+
it "formats correctly" do
|
33
|
+
Array.month_options(:format => "Up")[1][0].should == "JANUARY"
|
34
|
+
Array.month_options(:format => "Down")[1][0].should == "january"
|
35
|
+
Array.month_options(:format => "Cap")[1][0].should == "January"
|
36
|
+
Array.month_options(:format => "Up", :abbrev => true)[1][0].should == "JAN"
|
37
|
+
Array.month_options(:format => "Down", :abbrev => true)[1][0].should == "jan"
|
38
|
+
Array.month_options(:format => "Cap", :abbrev => true)[1][0].should == "Jan"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
23
42
|
describe "#options_label_for" do
|
24
43
|
it "returns the correct label" do
|
25
44
|
Array.us_state_options.options_label_for("AK").should == "Alaska"
|
data/spec/object/core_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corelib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corlew Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.1.11
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: '"Useful extensions & additions to the Ruby core classes'
|