rb_cfg_parser 0.0.2 → 0.1.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +145 -5
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53d596560d131b757edbbb6366355fb61abbd23b3f2af43ef2cd340f3dad408d
4
- data.tar.gz: aefe4e5a4049d4d27c401cc277d5258c6efd0a4a80d36d4986210ac15a3f0cf0
3
+ metadata.gz: 4df70690cfafd3255e28fdd3c4954dae237103d97b12eb74f99d8070dd32d0a8
4
+ data.tar.gz: eed8ed48485581ec18325ca84315b7eefd2350bcb3eeb220f0d1ed503186df98
5
5
  SHA512:
6
- metadata.gz: f77a2803b3baac5592a660e851dd460c67ed3c113f2c6c8f3dc809d478bad2c7757b7e7c3eae13a2a59c39189ada5d920d767f57e7534e329804675a4552b2bb
7
- data.tar.gz: c832cffd945b30329cee4c9ab0b98c5b280dac126d228b500d1c9adea4b8ffdaf79bb4cf25e4030d5171dc9471f3de4ad352b91808ca26b6070d0a90c3fe9b3a
6
+ metadata.gz: 1d657635a43aa04c046a0f96ad369b0d9e9ce705ff2493120af7f2e31ac041480795f774a79fbd0b96ff3597dd6dab4acb9ac19a6f13c7c1a744bf84ae16d0a4
7
+ data.tar.gz: e944e9320ba30df3f257e691e2947167d24d5ec7f1bb4cfd70ea6d51ea34a7ca98f95df736da71eb1fc9c6e2eea613c340d27edceea42e87579600b57675615b
data/README.md CHANGED
@@ -1,10 +1,17 @@
1
- website: <https://link-here>
1
+ * website: <https://arrizza.com/rb-cfg-parser.html>
2
+ * installation: see <https://arrizza.com/setup-common.html>
2
3
 
3
4
  ## Summary
4
5
 
5
- This project TODO...
6
+ This Ruby gem parses a .cfg file based on how python's ```configparser``` module works.
6
7
 
7
- * run
8
+ The need for this came from a "cross-platform utilities" (xplat_utils) repo that I use
9
+ to maintain the many projects for my website. It works on Python, Ruby, C/C++, Android
10
+ for now.
11
+
12
+ Having a common .cfg format is ideal in that scenario.
13
+
14
+ * sample run
8
15
 
9
16
  ```bash
10
17
  ./doit
@@ -13,10 +20,143 @@ This project TODO...
13
20
  Typical output:
14
21
 
15
22
  ```bash
16
- TODO
23
+ >> cfg:
24
+ >> version: 0.0.2
25
+ >> mod_name: rb-cfg-parser
26
+ >> desc: ruby gem to parse and load .cfg files
27
+ >> slug: {mod_name}
28
+ >>
29
+ doit: run_it rc=0
17
30
  ```
18
31
 
19
32
  ## How to use
20
33
 
21
- TODO
34
+ See sample/main.rb for an example of how to run it:
35
+
36
+ ```ruby
37
+ parser = RbCfgParser.new
38
+ cfg = parser.parse_file('xplat.cfg')
39
+ puts(' >> cfg:')
40
+ puts(" >> version: #{cfg['xplat']['version']}")
41
+ puts(" >> mod_name: #{cfg['xplat']['mod_name']}")
42
+ puts(" >> desc: #{cfg['xplat']['desc']}")
43
+ puts(' >>')
44
+ ```
45
+
46
+ See ut/ut_*.rb for examples of all the possible formats it recognizes.
47
+
48
+ #### parsing
49
+
50
+ A cfg file can be parsed or a string can be parsed:
51
+
52
+ ```ruby
53
+ parser = RbCfgParser.new
54
+ cfg = parser.parse_file('xplat.cfg')
55
+ cfg = parser.parse_str(lines)
56
+ ```
57
+
58
+ The content returned is a hash.
59
+ The key is the section_name and the variables within that
60
+ section are held as a hash.
61
+
62
+ ```text
63
+ [section_name]
64
+ variable = value
65
+ # cfg['section_name']['variable'] == 'value'
66
+ ```
67
+
68
+ #### comments
69
+
70
+ Line comments are allowed. Lines starting with ';' or '#' are considered comments
71
+
72
+ ```text
73
+ ; comment 1
74
+ # comment 2
75
+ ```
76
+
77
+ Trailing comments are not recommended.
78
+ They may work okay but may also cause problems:
79
+
80
+ ```
81
+ [sect1] # comment 1 <== will be ignored
82
+ vrbl1 = val1
83
+ val2 ; comment2 <== will be part of the values in vrbl1
84
+ ```
85
+
86
+ #### sections
87
+
88
+ In the cfg, a section names a group of variables.
89
+
90
+ Sections are wrapped in square brackets:
22
91
 
92
+ ```text
93
+ [section_a]
94
+ [section b]
95
+ [ section c ] # leading/trailing spaces are stripped, the section name is "section c"
96
+ ```
97
+
98
+ There is an :unnamed section automatically declared:
99
+
100
+ ```text
101
+ vrbl1 = val1 # held in section :unnamed , cfg[:unname]['vrbl1'] == 'val1'
102
+ [sect1]
103
+ vrbl2 = val2
104
+ ```
105
+
106
+ #### variables and values
107
+
108
+ Variables may have one value.
109
+ The value may be single- or double-quoted
110
+
111
+ ```text
112
+ # these all hold the same value 'val1'
113
+ vrbl1 = val1
114
+ vrbl1 = 'val1'
115
+ vrbl1 = "val1"
116
+ ```
117
+
118
+ Variables may have no/empty value:
119
+
120
+ ```text
121
+ # these all hold the same value ''
122
+ vrbl1 =
123
+ vrbl1 = ''
124
+ vrbl1 = ""
125
+ ```
126
+
127
+ Variables may have multiple values:
128
+
129
+ ```text
130
+ # these all hold the same array ['val1', 'val2', 'val3']
131
+ vrbl1 = val1 val2 val3
132
+ vrbl1 = 'val1' 'val2' 'val3'
133
+ vrbl1 = "val1" "val2" "val3"
134
+ ```
135
+
136
+ Warning: there is currently an issue is inconsistent quoting is done:
137
+
138
+ ```text
139
+ # these will return the incorrect array ['val1', 'val3']
140
+ vrbl1 = 'val1' val2 'val3'
141
+ vrbl1 = 'val1' "val2" 'val3'
142
+ vrbl1 = "val1" 'val2' "val3"
143
+ ```
144
+
145
+ Variables may be on multiple lines:
146
+
147
+ ```text
148
+ # this returns an array ['val1', 'val2', 'val3']
149
+ vrbl1 = 'val1'
150
+ 'val2'
151
+ 'val3'
152
+ ```
153
+
154
+ Note mixed quoted are okay, but recommended since converting them to a single
155
+ line will cause errors
156
+
157
+ ```text
158
+ # this returns an array ['val1', 'val2', 'val3']
159
+ vrbl1 = 'val1'
160
+ val2
161
+ "val3"
162
+ ```
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_cfg_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - John Arrizza
7
+ - J. Arrizza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2025-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ruby gem to parse and load .cfg files
14
- email: cppgent@gmail.com
14
+ email: cppgent0@gmail.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []