functional_support 0.0.5 → 0.0.6
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/functional_support.rb +4 -0
- data/lib/functional_support/core_ext/array.rb +8 -0
- data/lib/functional_support/core_ext/class/attribute_accessors.rb +36 -0
- data/lib/functional_support/core_ext/float.rb +13 -0
- data/lib/functional_support/core_ext/hash.rb +21 -0
- data/lib/functional_support/core_ext/integer.rb +18 -0
- data/lib/functional_support/core_ext/string.rb +22 -0
- data/lib/functional_support/version.rb +1 -1
- metadata +20 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0a99393a71e9cb74719aab4fe80e375ba840c9b
|
|
4
|
+
data.tar.gz: ec055253358caf4859274a751e6ae3e30cf904ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 924759344b05cdf756a54c3c112715ab39ce6248b93b723a1a6d022c850e887486c7a1b6bcc991c6dbc66fe02262e972f9d6fa164dd48edd0dd7196fdd98bfe8
|
|
7
|
+
data.tar.gz: ab175281e867eec144b5e8cfaca2c73f9b28487b59a89f917b7c0d701455561c04a3569a7e7d3521f9bca245b16db97ec913d2656f7dd29fbf924440843775d8
|
data/lib/functional_support.rb
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
require "functional_support/version"
|
|
2
2
|
require 'functional_support/core_ext/array'
|
|
3
3
|
require 'functional_support/core_ext/hash'
|
|
4
|
+
require 'functional_support/core_ext/integer'
|
|
5
|
+
require 'functional_support/core_ext/string'
|
|
6
|
+
require 'functional_support/core_ext/class/attribute_accessors'
|
|
7
|
+
require 'functional_support/core_ext/float'
|
|
4
8
|
module FunctionalSupport
|
|
5
9
|
# Your code goes here...
|
|
6
10
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class Class
|
|
2
|
+
|
|
3
|
+
def attr_hash_reader(*syms)
|
|
4
|
+
options = syms.extract_options!
|
|
5
|
+
hash_name = options[:store_in].to_s if options[:store_in].present?
|
|
6
|
+
hash_name ||= "attributes"
|
|
7
|
+
syms.each do |sym|
|
|
8
|
+
raise NameError.new("invalid instance attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
|
|
9
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
|
10
|
+
def #{sym}
|
|
11
|
+
(@#{hash_name} ||= {})[:#{sym}]
|
|
12
|
+
end
|
|
13
|
+
EOS
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def attr_hash_writer(*syms)
|
|
18
|
+
options = syms.extract_options!
|
|
19
|
+
hash_name = options[:store_in].to_s if options[:store_in].present?
|
|
20
|
+
hash_name ||= "attributes"
|
|
21
|
+
syms.each do |sym|
|
|
22
|
+
raise NameError.new("invalid instance attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
|
|
23
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
|
24
|
+
def #{sym}=(obj)
|
|
25
|
+
@#{hash_name} ||= {}
|
|
26
|
+
@#{hash_name}[:#{sym}] = obj
|
|
27
|
+
end
|
|
28
|
+
EOS
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def attr_hash_accessor(*syms)
|
|
33
|
+
attr_hash_writer *syms
|
|
34
|
+
attr_hash_reader *syms
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
class Hash
|
|
2
|
+
class EnforcedKeyMissing < StandardError; end
|
|
2
3
|
class HashProc < Proc
|
|
3
4
|
def to(key)
|
|
4
5
|
call key
|
|
@@ -30,6 +31,14 @@ class Hash
|
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
34
|
+
def enforce!(*keys)
|
|
35
|
+
keys.reduce(self.class.new) do |hash, key|
|
|
36
|
+
raise EnforcedKeyMissing.new("#{key} is blank") if self[key].blank?
|
|
37
|
+
hash[key] = self[key]
|
|
38
|
+
hash
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
33
42
|
def permit(*keys)
|
|
34
43
|
keys.reduce(self.class.new) do |hash, key|
|
|
35
44
|
hash[key] = self[key] if self[key].present?
|
|
@@ -37,6 +46,18 @@ class Hash
|
|
|
37
46
|
end
|
|
38
47
|
end
|
|
39
48
|
|
|
49
|
+
def key_map(&block)
|
|
50
|
+
clone.key_map!(&block)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def key_map!(&block)
|
|
54
|
+
tap do |hash|
|
|
55
|
+
hash.keys.each do |key|
|
|
56
|
+
hash[yield(key)] = hash.delete key if hash.has_key? key
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
40
61
|
def alter_key_from!(from_key)
|
|
41
62
|
HashProc.new do |to_key|
|
|
42
63
|
new_value = self.delete from_key
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Integer
|
|
2
|
+
# map this number to a lowercased alphabet letter
|
|
3
|
+
# 0-25 goes to a-z
|
|
4
|
+
# 26-52 goes to aa-zz, etc.
|
|
5
|
+
def to_alphabet
|
|
6
|
+
qm = divmod 26
|
|
7
|
+
return _convert_to_letter qm.last if qm.first.abs.zero?
|
|
8
|
+
return qm.first.to_alphabet + _convert_to_letter(qm.last)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def _convert_to_letter(v)
|
|
14
|
+
raise Math::DomainError, "#{v} is outside the range of the English alphabet" if v > 25
|
|
15
|
+
@@_the_alphabet_of_lowercase_letters ||= ('a'...'z').to_a.append('z')
|
|
16
|
+
@@_the_alphabet_of_lowercase_letters[v.to_i.abs]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class String
|
|
2
|
+
|
|
3
|
+
# Appends crap to the string until the given string satisfies the given condition
|
|
4
|
+
def append_until(content=" ", &condition)
|
|
5
|
+
return self if yield self
|
|
6
|
+
(self + content).append_until(content, &condition)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def prepend_until(content=" ", &condition)
|
|
10
|
+
return self if yield self
|
|
11
|
+
(content + self).prepend_until(content, &condition)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def consume(diet="")
|
|
15
|
+
return self if diet.blank? or self.blank?
|
|
16
|
+
if self[0] == diet[0]
|
|
17
|
+
self[1..-1].consume diet[1..-1]
|
|
18
|
+
else
|
|
19
|
+
throw "Mismatched diet error #{diet} does not match #{self}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: functional_support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Chen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.3'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - ~>
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '2.13'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - ~>
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '2.13'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: activesupport
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- -
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '2.3'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- -
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '2.3'
|
|
69
69
|
description: Core extensions on array and hash I find useful for everyday development
|
|
@@ -73,8 +73,8 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
-
- .gitignore
|
|
77
|
-
- .rspec
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
78
|
- Gemfile
|
|
79
79
|
- LICENSE.txt
|
|
80
80
|
- README.md
|
|
@@ -82,7 +82,11 @@ files:
|
|
|
82
82
|
- functional_support.gemspec
|
|
83
83
|
- lib/functional_support.rb
|
|
84
84
|
- lib/functional_support/core_ext/array.rb
|
|
85
|
+
- lib/functional_support/core_ext/class/attribute_accessors.rb
|
|
86
|
+
- lib/functional_support/core_ext/float.rb
|
|
85
87
|
- lib/functional_support/core_ext/hash.rb
|
|
88
|
+
- lib/functional_support/core_ext/integer.rb
|
|
89
|
+
- lib/functional_support/core_ext/string.rb
|
|
86
90
|
- lib/functional_support/version.rb
|
|
87
91
|
- spec/spec_helper.rb
|
|
88
92
|
homepage: ''
|
|
@@ -95,20 +99,21 @@ require_paths:
|
|
|
95
99
|
- lib
|
|
96
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
101
|
requirements:
|
|
98
|
-
- -
|
|
102
|
+
- - ">="
|
|
99
103
|
- !ruby/object:Gem::Version
|
|
100
104
|
version: '0'
|
|
101
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
106
|
requirements:
|
|
103
|
-
- -
|
|
107
|
+
- - ">="
|
|
104
108
|
- !ruby/object:Gem::Version
|
|
105
109
|
version: '0'
|
|
106
110
|
requirements: []
|
|
107
111
|
rubyforge_project:
|
|
108
|
-
rubygems_version: 2.
|
|
112
|
+
rubygems_version: 2.2.1
|
|
109
113
|
signing_key:
|
|
110
114
|
specification_version: 4
|
|
111
115
|
summary: Includes a lot of stuff on higher order functional processing of arrays and
|
|
112
116
|
hashes
|
|
113
117
|
test_files:
|
|
114
118
|
- spec/spec_helper.rb
|
|
119
|
+
has_rdoc:
|