shrift 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +13 -0
- data/lib/shrift/shrift_map.rb +5 -5
- data/lib/shrift/shrift_mapper.rb +12 -12
- data/lib/shrift/shrift_version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4bfec4ab473bf34570817c08cc69a55c2768bb9
|
4
|
+
data.tar.gz: 3a23d7520579fdb6f9cdd3a407f5ba10ed4bc51e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f8d933bb61710667bf5fc28dd87fd99513a3f4b26aac25910077499254d13221304db858244a231b9f6d6f6af0bab38861705906c2bea3868904b649fa3721f
|
7
|
+
data.tar.gz: 8ce25d22f9767651723117765a5cfbd72f3b1354a03d12da2b7c2212440cdec2045a79bb79ece918bcf569d8ba4fd9d50584a76902f8562a3284f5c51340c95e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Shrift
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/shrift.svg)](https://badge.fury.io/rb/shrift)
|
3
4
|
[![Build Status](https://travis-ci.org/folkengine/shrift.svg?branch=master)](https://travis-ci.org/folkengine/shrift)
|
4
5
|
|
5
6
|
Makes short shrift of objects.
|
@@ -10,6 +11,18 @@ This is alpha software and only works with basic Objects.
|
|
10
11
|
|
11
12
|
Shrift is a simple DSL generator that turns Objects to single line Strings for easy storage and debugging.
|
12
13
|
|
14
|
+
An example 'Shrift String' would be:
|
15
|
+
|
16
|
+
example:st15dx14cn10w18i3ch6:4
|
17
|
+
|
18
|
+
When you split the String on ':', this first cell is a String, the second cell is a 'Shrift Map' of alternating
|
19
|
+
field shorthand Strings and integers, and the third cell maps to an integer.
|
20
|
+
|
21
|
+
Pass this String back into the Shrift object configured to make short shrift of the class and it will return the Object,
|
22
|
+
good as new.
|
23
|
+
|
24
|
+
I created this so that I had a way to pack as much informational punch into as short a space as possible.
|
25
|
+
|
13
26
|
## Installation
|
14
27
|
|
15
28
|
Add this line to your application's Gemfile:
|
data/lib/shrift/shrift_map.rb
CHANGED
@@ -6,24 +6,24 @@ require_relative 'shrift_exception'
|
|
6
6
|
# Shrift map keys are lowercase.
|
7
7
|
#
|
8
8
|
class ShriftMap
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :schema, :shrift_map_string
|
10
10
|
|
11
11
|
def initialize(shrift_map_string)
|
12
12
|
@shrift_map_string = shrift_map_string
|
13
|
-
@
|
13
|
+
@schema = {}
|
14
14
|
split(shrift_map_string)
|
15
15
|
end
|
16
16
|
|
17
17
|
def fetch(key)
|
18
|
-
@
|
18
|
+
@schema[key.downcase.to_sym].to_i
|
19
19
|
end
|
20
20
|
|
21
21
|
def store(key, value)
|
22
|
-
@
|
22
|
+
@schema[key.downcase.to_sym] = value.to_i
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_hash
|
26
|
-
@
|
26
|
+
@schema
|
27
27
|
end
|
28
28
|
|
29
29
|
def to_s
|
data/lib/shrift/shrift_mapper.rb
CHANGED
@@ -2,38 +2,38 @@ require_relative 'shrift_map'
|
|
2
2
|
|
3
3
|
# I map ShriftMaps
|
4
4
|
class ShriftMapper
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :schema
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(schema: {})
|
8
|
+
@schema = schema
|
9
9
|
clean
|
10
10
|
end
|
11
11
|
|
12
12
|
def fetch(key)
|
13
|
-
@
|
13
|
+
@schema[key.downcase.to_sym]
|
14
14
|
end
|
15
15
|
|
16
16
|
def store(key, value)
|
17
|
-
@
|
17
|
+
@schema[key] = value
|
18
18
|
end
|
19
19
|
|
20
20
|
def parse(shrift_map_string)
|
21
21
|
hash = {}
|
22
|
-
ShriftMap.new(shrift_map_string).
|
23
|
-
hash[@
|
22
|
+
ShriftMap.new(shrift_map_string).schema.each do |key, val|
|
23
|
+
hash[@schema[key]] = val
|
24
24
|
end
|
25
25
|
hash
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_hash
|
29
|
-
@
|
29
|
+
@schema
|
30
30
|
end
|
31
31
|
|
32
32
|
# :reek:UncommunicativeVariableName :reek:FeatureEnvy
|
33
33
|
def to_shrift_string(mappie)
|
34
34
|
return mappie if mappie.is_a?(String)
|
35
|
-
return mappie.map { |k, v| @
|
36
|
-
@
|
35
|
+
return mappie.map { |k, v| @schema.key(k).to_s.downcase + v.to_s }.join if mappie.is_a?(Hash)
|
36
|
+
@schema.map { |k, v| k.to_s.downcase + mappie.send(v).to_s }.join
|
37
37
|
end
|
38
38
|
|
39
39
|
def to_shrift_map(mappie)
|
@@ -49,13 +49,13 @@ class ShriftMapper
|
|
49
49
|
# :reek:UncommunicativeVariableName
|
50
50
|
def set(value, target)
|
51
51
|
shrift_map = to_shrift_map(value)
|
52
|
-
@
|
52
|
+
@schema.map { |k, v| target.send("#{v}=", shrift_map.fetch(k)) }
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
57
|
# Convert Hash keys to symbols
|
58
58
|
def clean
|
59
|
-
@
|
59
|
+
@schema = Hash[@schema.map { |key, value| [key.downcase.to_sym, value] }]
|
60
60
|
end
|
61
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Folkengine
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|