format_engine 0.0.2 → 0.1.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 +29 -14
- data/lib/format_engine/format_spec.rb +8 -7
- data/lib/format_engine/spec_info.rb +5 -5
- data/lib/format_engine/version.rb +1 -1
- data/mocks/demo/demo_parse.rb +3 -3
- data/tests/parser_engine_tests.rb +7 -7
- 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: 9763561c83301a57758ba138e2a5e1baceaa9bd2
|
4
|
+
data.tar.gz: a358fc3401bc95e897b7eb3470e3a0583d1699d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ae5fcb562aa0a10b91dd6f7d599f8b50154e445e4fe56b62833e0d8d0e673cd49cca5295e24d86f0dbdfce542aabad41111e8688b7bc7462b2333c1043c995
|
7
|
+
data.tar.gz: 4894677c3a40eacf60946cf13b4d10e8d71a441283b81f5a2b7529a1d6a9cbe8fd08cd7992e614f67c58dc982a2158a4f53572313a612d5b4db5639b7e670abe
|
data/README.md
CHANGED
@@ -54,9 +54,9 @@ class Customer
|
|
54
54
|
|
55
55
|
#Demo defn of the strprs method for formatted string input!
|
56
56
|
attr_parser :strprs,
|
57
|
-
{"%f" => lambda {
|
58
|
-
"%l" => lambda {
|
59
|
-
:after => lambda { set dst.new(
|
57
|
+
{"%f" => lambda { tmp[:fn] = found if parse(/(\w)+/ ) },
|
58
|
+
"%l" => lambda { tmp[:ln] = found if parse(/(\w)+/ ) },
|
59
|
+
:after => lambda { set dst.new(tmp[:fn], tmp[:ln]) } }
|
60
60
|
|
61
61
|
#Create an instance of the demo customer.
|
62
62
|
def initialize(first_name, last_name)
|
@@ -81,19 +81,22 @@ agent = Customer.strprs(in_str, "%f, %l")
|
|
81
81
|
|
82
82
|
Format String Specification Syntax (BNF):
|
83
83
|
|
84
|
-
* spec =
|
85
|
-
* item = "%"
|
86
|
-
* flag =
|
84
|
+
* spec = ( text | item )+
|
85
|
+
* item = "%" flag* (parm ("." parm)?)? command
|
86
|
+
* flag = ( "~" | "@" | "#" | "&" | "^" |
|
87
87
|
"&" | "*" | "-" | "+" | "=" |
|
88
88
|
"?" | "_" | "<" | ">" | "\\" |
|
89
|
-
"/" | "." | "," | "|" | "!"
|
90
|
-
* parm =
|
91
|
-
* command =
|
89
|
+
"/" | "." | "," | "|" | "!" )
|
90
|
+
* parm = ("0" .. "9")+
|
91
|
+
* command = ("a" .. "z" | "A" .. "Z")
|
92
92
|
|
93
93
|
|
94
|
-
###
|
94
|
+
###Samples:
|
95
95
|
|
96
|
-
The format specification
|
96
|
+
The format specification:
|
97
|
+
```ruby
|
98
|
+
"Elapsed = %*02H:%M:%5.2S!"
|
99
|
+
```
|
97
100
|
creates the following format specification array:
|
98
101
|
|
99
102
|
```ruby
|
@@ -123,11 +126,11 @@ Attributes:
|
|
123
126
|
* dst - A string that receives the formatted output (RO).
|
124
127
|
* fmt - The format specification currently being processed (RW).
|
125
128
|
* engine - The formatting engine. Mostly for access to the library (RO).
|
126
|
-
*
|
129
|
+
* tmp - A utility hash so that the formatting process can retain state (RO).
|
127
130
|
|
128
131
|
Methods
|
129
132
|
* cat - Append the string that follows to the formatted output. This is
|
130
|
-
equivalent to dst << "string"
|
133
|
+
equivalent to the code dst << "string"
|
131
134
|
|
132
135
|
###When Parsing:
|
133
136
|
Attributes:
|
@@ -135,7 +138,7 @@ Attributes:
|
|
135
138
|
* dst - The class of the object being created (RO).
|
136
139
|
* fmt - The parse specification currently being processed (RW).
|
137
140
|
* engine - The parsing engine. Mostly for access to the library (RO).
|
138
|
-
*
|
141
|
+
* tmp - A utility hash so that the parsing process can retain state (RO).
|
139
142
|
|
140
143
|
Methods
|
141
144
|
* set - Set the return value of the parsing operation to the value that follows.
|
@@ -162,8 +165,20 @@ most welcomed.
|
|
162
165
|
|
163
166
|
## Contributing
|
164
167
|
|
168
|
+
#### Plan A
|
169
|
+
|
165
170
|
1. Fork it ( https://github.com/[my-github-username]/format_engine/fork )
|
166
171
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
167
172
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
168
173
|
4. Push to the branch (`git push origin my-new-feature`)
|
169
174
|
5. Create a new Pull Request
|
175
|
+
|
176
|
+
#### Plan B
|
177
|
+
|
178
|
+
Go to the GitHub repository and raise an issue calling attention to some
|
179
|
+
aspect that could use some TLC or a suggestion or idea. Apply labels to
|
180
|
+
the issue that match the point you are trying to make. Then follow your
|
181
|
+
issue and keep up-to-date as it is worked on. Or not as pleases you.
|
182
|
+
All input are greatly appreciated.
|
183
|
+
|
184
|
+
|
@@ -2,15 +2,16 @@ require_relative 'format_spec/literal'
|
|
2
2
|
require_relative 'format_spec/variable'
|
3
3
|
|
4
4
|
# Format String Specification Syntax (BNF):
|
5
|
-
# spec =
|
6
|
-
# item = "%"
|
7
|
-
# flag =
|
5
|
+
# spec = (text | item)+
|
6
|
+
# item = "%" flag* (parm ("." parm)? )? command
|
7
|
+
# flag = ( "~" | "@" | "#" | "&" | "^" |
|
8
8
|
# "&" | "*" | "-" | "+" | "=" |
|
9
9
|
# "?" | "_" | "<" | ">" | "\\" |
|
10
|
-
# "/" | "." | "," | "|" | "!"
|
11
|
-
# parm =
|
12
|
-
# command =
|
13
|
-
#
|
10
|
+
# "/" | "." | "," | "|" | "!" )
|
11
|
+
# parm = ("0" .. "9" )+
|
12
|
+
# command = ("a" .. "z" | "A" .. "Z")
|
13
|
+
#
|
14
|
+
# Sample: x = FormatSpec.get_spec "Elapsed = %*3.1H:%02M!"
|
14
15
|
|
15
16
|
module FormatEngine
|
16
17
|
|
@@ -11,7 +11,7 @@ module FormatEngine
|
|
11
11
|
#* dst - A string that receives the formatted output.
|
12
12
|
#* fmt - The format specification currently being processed.
|
13
13
|
#* engine - The formatting engine. Mostly for access to the library.
|
14
|
-
#*
|
14
|
+
#* tmp - A utility hash so that the formatting process can retain state.
|
15
15
|
#<br>Methods
|
16
16
|
#* cat - Append the string that follows to the formatted output.
|
17
17
|
#<br>
|
@@ -20,7 +20,7 @@ module FormatEngine
|
|
20
20
|
#* dst - The class of the object being created.
|
21
21
|
#* fmt - The parse specification currently being processed.
|
22
22
|
#* engine - The parsing engine. Mostly for access to the library.
|
23
|
-
#*
|
23
|
+
#* tmp - A utility hash so that the parsing process can retain state.
|
24
24
|
#<br>Methods
|
25
25
|
#* set - Set the return value of the parsing operation to the value that follows.
|
26
26
|
#* parse - Look for the string or regex parm that follows. Return the data found or nil.
|
@@ -30,14 +30,14 @@ module FormatEngine
|
|
30
30
|
class SpecInfo
|
31
31
|
|
32
32
|
# General readers
|
33
|
-
attr_reader :src, :dst, :engine, :
|
33
|
+
attr_reader :src, :dst, :engine, :tmp
|
34
34
|
|
35
35
|
#General accessors
|
36
36
|
attr_accessor :fmt
|
37
37
|
|
38
38
|
# Set up the spec info.
|
39
|
-
def initialize(src, dst, fmt, engine,
|
40
|
-
@src, @dst, @fmt, @engine, @
|
39
|
+
def initialize(src, dst, fmt, engine, tmp = {})
|
40
|
+
@src, @dst, @fmt, @engine, @tmp = src, dst, fmt, engine, tmp
|
41
41
|
end
|
42
42
|
|
43
43
|
# Concatenate onto the formatted output string.
|
data/mocks/demo/demo_parse.rb
CHANGED
@@ -7,8 +7,8 @@ class Customer
|
|
7
7
|
#The specification of the parser method of the demo \Customer class.
|
8
8
|
|
9
9
|
attr_parser :strprs,
|
10
|
-
{"%f" => lambda {
|
11
|
-
"%l" => lambda {
|
12
|
-
:after => lambda { set dst.new(
|
10
|
+
{"%f" => lambda { tmp[:fn] = found if parse(/(\w)+/ ) },
|
11
|
+
"%l" => lambda { tmp[:ln] = found if parse(/(\w)+/ ) },
|
12
|
+
:after => lambda { set dst.new(tmp[:fn], tmp[:ln]) } }
|
13
13
|
|
14
14
|
end
|
@@ -13,18 +13,18 @@ class ParserTester < Minitest::Test
|
|
13
13
|
|
14
14
|
def make_parser
|
15
15
|
FormatEngine::Engine.new(
|
16
|
-
"%f" => lambda {
|
17
|
-
"%F" => lambda {
|
18
|
-
"%-F" => lambda {
|
19
|
-
"%l" => lambda {
|
20
|
-
"%L" => lambda {
|
21
|
-
"%-L" => lambda {
|
16
|
+
"%f" => lambda { tmp[:fn] = found if parse(/(\w)+/ ) },
|
17
|
+
"%F" => lambda { tmp[:fn] = found.upcase if parse(/(\w)+/) },
|
18
|
+
"%-F" => lambda { tmp[:fn] = found.capitalize if parse(/(\w)+/) },
|
19
|
+
"%l" => lambda { tmp[:ln] = found if parse(/(\w)+/ ) },
|
20
|
+
"%L" => lambda { tmp[:ln] = found.upcase if parse(/(\w)+/) },
|
21
|
+
"%-L" => lambda { tmp[:ln] = found.capitalize if parse(/(\w)+/) },
|
22
22
|
"%s" => lambda { parse(/\s+/) },
|
23
23
|
"%,s" => lambda { parse(/[,\s]\s*/) },
|
24
24
|
"%t" => lambda { parse("\t") },
|
25
25
|
"%!t" => lambda { parse!("\t") },
|
26
26
|
|
27
|
-
:after => lambda { set TestPerson.new(
|
27
|
+
:after => lambda { set TestPerson.new(tmp[:fn], tmp[:ln]) })
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_that_it_can_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.0
|
4
|
+
version: 0.1.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: 2015-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|