fat_core 5.6.0 → 5.6.1
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 +4 -4
- data/lib/fat_core/symbol.rb +7 -4
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/string_spec.rb +1 -0
- data/spec/lib/symbol_spec.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6cdea468a6e0d1208469b2d079d89694e3f70d62f8c9805e8f7372677430127
|
4
|
+
data.tar.gz: bb58238999c2d549e834f28a7dc300be835dbf3b3ef722c92f57480c0c426dd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 685e201065051cf82122aa799e2f08fb5ea44c6e5cccf3a454dd3389dfbb2af8cdf4b0bcffbc5d1e68571af8c9e96328d7272a9eb16ffd14194bd6a2f9a45150
|
7
|
+
data.tar.gz: 50c4b04bfb61fd22005add98c38a8cd0b29a8d67a479512dbc08f3c34f35669fbc93d8958a89fc3c8f2807c17935e3a451d4ad9755e0dbfb7cfd30568596c321
|
data/lib/fat_core/symbol.rb
CHANGED
@@ -16,13 +16,15 @@ module FatCore
|
|
16
16
|
to_s.tr('_', ' ').split.join(' ').entitle
|
17
17
|
end
|
18
18
|
|
19
|
-
# Return self
|
20
|
-
#
|
21
|
-
#
|
19
|
+
# Return self in a form suitable as an identifier. Ruby allows symbols to
|
20
|
+
# have arbitrary characters in them that are not permitted as an
|
21
|
+
# identifier. Convert this symbol to one that is a legal identifier. This
|
22
|
+
# (together with String#as_sym) allows `#as_sym` to be applied to a string
|
23
|
+
# or Symbol and get back a Symbol with out testing for type.
|
22
24
|
#
|
23
25
|
# @return [Symbol] just self
|
24
26
|
def as_sym
|
25
|
-
|
27
|
+
as_str.as_sym
|
26
28
|
end
|
27
29
|
|
28
30
|
# Convert this symbol to a string in such a manner that for simple cases,
|
@@ -31,6 +33,7 @@ module FatCore
|
|
31
33
|
to_s
|
32
34
|
.downcase
|
33
35
|
.tr('_', '-')
|
36
|
+
.gsub(/\s+/, '_')
|
34
37
|
.gsub(/[^-_A-Za-z0-9]/, '')
|
35
38
|
end
|
36
39
|
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/string_spec.rb
CHANGED
@@ -196,6 +196,7 @@ the people, for the people, shall not perish from the earth."
|
|
196
196
|
expect('jack_in-the-box'.as_sym).to eq :jack_in_the_box
|
197
197
|
expect('jack_in_the_box'.as_sym).to eq :jack_in_the_box
|
198
198
|
expect('Jack in the Box'.as_sym).to eq :jack_in_the_box
|
199
|
+
expect("Four Score \t\n and 7 years ago".as_sym).to eq :four_score_and_7_years_ago
|
199
200
|
end
|
200
201
|
|
201
202
|
it 'does nothing in response to as_str' do
|
data/spec/lib/symbol_spec.rb
CHANGED
@@ -11,13 +11,18 @@ describe Symbol do
|
|
11
11
|
expect(:i_am_a_symbol.tex_quote).to eq 'i\\_am\\_a\\_symbol'
|
12
12
|
end
|
13
13
|
|
14
|
-
it '
|
14
|
+
it 'return self :as_sym as a symbol but also a legal identifier' do
|
15
15
|
expect(:i_am_a_symbol.as_sym).to eq :i_am_a_symbol
|
16
|
+
expect(:'i-am-a_symbol'.as_sym).to eq :i_am_a_symbol
|
17
|
+
expect(:'Four Score and 7 years ago'.as_sym).to eq :four_score_and_7_years_ago
|
18
|
+
expect(:four_score_and_7_years_ago.as_sym).to eq :four_score_and_7_years_ago
|
16
19
|
end
|
17
20
|
|
18
21
|
it 'as_str is the inverse of as_sym for simple cases' do
|
19
22
|
expect('jack-in-the-box'.as_sym.as_str).to eq 'jack-in-the-box'
|
20
23
|
expect('jack_in-the-box'.as_sym.as_str).to eq 'jack-in-the-box'
|
21
24
|
expect('jack_in-the-box'.as_sym.as_str).to eq 'jack-in-the-box'
|
25
|
+
expect(:four_score_and_7_years_ago.as_str).to eq 'four-score-and-7-years-ago'
|
26
|
+
expect(:four_score_and_7_years_ago.as_str.as_sym).to eq :four_score_and_7_years_ago
|
22
27
|
end
|
23
28
|
end
|