format_engine 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/format_engine/attr_formatter.rb +1 -0
- data/lib/format_engine/attr_parser.rb +1 -0
- data/lib/format_engine/format_spec/literal.rb +4 -1
- data/lib/format_engine/version.rb +1 -1
- data/tests/parser_engine_tests.rb +17 -3
- 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: b0baee6898a0254f3c7e17992bdb405855786cde
|
4
|
+
data.tar.gz: e4ed97834beefe97848e7c45e9a8bbda13918b4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81baf16535d34920bfc19c3be71fe479fc728db0e0f07c9926b32e97c088a2072c241ea131e144d14ab19e2b8699875b0b50afedb82c1964e42f59ec73ea40f2
|
7
|
+
data.tar.gz: 2721ee739f1a909e8307612f55ff84a916b103b804b6108e2e89d612d191600ecd6f48a9766b806c83814b4b32e69baa5e7d3b4fe32d6610ae71d98feb789a0c
|
data/README.md
CHANGED
@@ -105,7 +105,8 @@ creates the following format specification array:
|
|
105
105
|
Variable("%S", ["-5", "2"]),
|
106
106
|
Literal("!")]
|
107
107
|
```
|
108
|
-
Where literals are processed as themselves
|
108
|
+
Where literals are processed as themselves. If that literal ends with a space,
|
109
|
+
that space will match zero or more spaces. Variables are executed by looking
|
109
110
|
up the format string in the library and executing the corresponding block.
|
110
111
|
|
111
112
|
**Note:** If a format string does not correspond to an entry in the library,
|
@@ -145,14 +146,15 @@ Methods
|
|
145
146
|
* found - The text found by the last parse (or parse!) operation.
|
146
147
|
|
147
148
|
###Format Specifier Attributes
|
148
|
-
The format specifier
|
149
|
+
The format specifier, used in both formatting and parsing and accessed as the
|
150
|
+
fmt attribute, has itself, the following attributes:
|
149
151
|
* has_width? - Was a width specified?
|
150
152
|
* width - The width parameter or 0 if not specified.
|
151
153
|
* width_str - The actual width text or an empty string.
|
152
154
|
* has_prec? - Was a precision specified?
|
153
155
|
* prec - The precision parameter or 0 if not specified.
|
154
156
|
* prec_str - The actual precision text or an empty string.
|
155
|
-
* parm_str - The actual parameter text or an empty string.
|
157
|
+
* parm_str - The actual parameter (width and precision) text or an empty string.
|
156
158
|
|
157
159
|
## Philosophy
|
158
160
|
|
@@ -9,6 +9,8 @@ module FormatEngine
|
|
9
9
|
# Set up a literal format specification.
|
10
10
|
def initialize(literal)
|
11
11
|
@literal = literal
|
12
|
+
@head = literal.rstrip
|
13
|
+
@tail = literal.end_with?(' ')
|
12
14
|
end
|
13
15
|
|
14
16
|
# Is this literal supported by the engine? YES!
|
@@ -23,7 +25,8 @@ module FormatEngine
|
|
23
25
|
|
24
26
|
# Parse from the input string
|
25
27
|
def do_parse(spec_info)
|
26
|
-
spec_info.parse!(
|
28
|
+
spec_info.parse!(@head) unless @head.empty?
|
29
|
+
spec_info.parse(/\s*/) if @tail
|
27
30
|
end
|
28
31
|
|
29
32
|
# Inspect for debugging.
|
@@ -19,8 +19,6 @@ class ParserTester < Minitest::Test
|
|
19
19
|
"%l" => lambda { tmp[:ln] = found if parse(/(\w)+/ ) },
|
20
20
|
"%L" => lambda { tmp[:ln] = found.upcase if parse(/(\w)+/) },
|
21
21
|
"%-L" => lambda { tmp[:ln] = found.capitalize if parse(/(\w)+/) },
|
22
|
-
"%s" => lambda { parse(/\s+/) },
|
23
|
-
"%,s" => lambda { parse(/[,\s]\s*/) },
|
24
22
|
"%t" => lambda { parse("\t") },
|
25
23
|
"%!t" => lambda { parse!("\t") },
|
26
24
|
|
@@ -59,12 +57,28 @@ class ParserTester < Minitest::Test
|
|
59
57
|
|
60
58
|
def test_that_it_can_flex_parse
|
61
59
|
engine = make_parser
|
62
|
-
spec = "%f
|
60
|
+
spec = "%f, %l"
|
61
|
+
|
62
|
+
#No spaces.
|
63
|
+
result = engine.do_parse("Squidly,Jones", TestPerson, spec)
|
64
|
+
|
65
|
+
assert_equal(TestPerson, result.class)
|
66
|
+
assert_equal("Squidly", result.first_name)
|
67
|
+
assert_equal("Jones", result.last_name)
|
68
|
+
|
69
|
+
#One space.
|
63
70
|
result = engine.do_parse("Squidly, Jones", TestPerson, spec)
|
64
71
|
|
65
72
|
assert_equal(TestPerson, result.class)
|
66
73
|
assert_equal("Squidly", result.first_name)
|
67
74
|
assert_equal("Jones", result.last_name)
|
75
|
+
|
76
|
+
#Two spaces.
|
77
|
+
result = engine.do_parse("Squidly, Jones", TestPerson, spec)
|
78
|
+
|
79
|
+
assert_equal(TestPerson, result.class)
|
80
|
+
assert_equal("Squidly", result.first_name)
|
81
|
+
assert_equal("Jones", result.last_name)
|
68
82
|
end
|
69
83
|
|
70
84
|
def test_that_it_can_tab_parse
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|