krakken 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 +15 -0
  2. data/lib/krakken.rb +38 -0
  3. metadata +47 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGM0MmZmNTQ5ZmQxMjdmZGZkYzg4NWU0MjQ0MTI1NjQxMGU2NTI4ZQ==
5
+ data.tar.gz: !binary |-
6
+ Y2VkNDY3YjJiZTUyNjYxZDAyMTVhYTkzYzEwZjc3MzBjZDMzZjkxMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZWZlYTQ1YmMxNTQ1YjlkMWRjYjI1NTRhMDMxNmQxNTk5NWVmNTU3YjljYTY5
10
+ M2QzYTg4ZmZkN2M2YjQ2MjI3ZmRhYjk3Yzk2OTM5ZGE4N2ZjMzM1NWJkMGE5
11
+ ZDg4YmEyYTlkYmZjN2RlYmQyZDAxMjUwYjQ2MjYyNzBlMzJkMDM=
12
+ data.tar.gz: !binary |-
13
+ NWI3MGI4NmQyNjA3NDVmNDExNzUwNzI2MTI2YTI5ODc1NjgyZGE3OTI2MWY3
14
+ MTA3MGZjNDA2NzcxZWNkZDU3MzJkZjRlMzUzNDhiZDMwN2Y5ZWM0MDA5NGNm
15
+ YTJjZjVkYjdhZmI2NDcwMTcwZmY2NzlmYmE5ZmEyM2JhYTJmMmE=
@@ -0,0 +1,38 @@
1
+ class Krakken
2
+
3
+ # The method used to parse the config files
4
+ def parse(config="settings.conf")
5
+
6
+ values = []
7
+
8
+ # Create a new File handler object
9
+ File.open(config, 'r') do |configfile|
10
+ # Keep parsing long as there is another unparsed line in the file
11
+ while (nextline = configfile.gets)
12
+ # Check to see if we are parsing a comment
13
+ if nextline[0] != "#"
14
+ # Remove the whitespace
15
+ nextline = nextline.gsub(/\s+/, '')
16
+ # Split the key from the value
17
+ # And add each to an array
18
+ splitvalues = nextline.split("=")
19
+ splitvalues.each {|object| values << object}
20
+ end
21
+ end
22
+ end
23
+ # Return the parsed values as a hash
24
+ return Hash[*values.flatten]
25
+ end
26
+
27
+ # The method used to save the config file
28
+ def write(settings, output="settings.conf")
29
+
30
+ # Create the config file as a string to be written to disk
31
+ config = settings.map{|k,v| "#{k} = #{v}\n"}.join('')
32
+
33
+ # And save
34
+ File.open(output, 'w') {|f| f.write(config)}
35
+
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: krakken
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Sheffres
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Krakken is able to parse files into a hash, and write a hash to a file.
14
+ It supports comments started with '#' when parsing, and outputs in the format of
15
+ '[key]=[value]'
16
+ email: samsheff@icloud.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/krakken.rb
22
+ homepage: https://github.com/samsheff/krakken
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Config file parser and generator
46
+ test_files: []
47
+ has_rdoc: