debian-control-parser 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 +7 -0
  2. data/lib/debian_control_parser.rb +69 -0
  3. metadata +76 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9246930aa46c7dfb44794dfea50d490be8416bd
4
+ data.tar.gz: 93aaf5b9723b608ba222e08492a9e5bf38f32bac
5
+ SHA512:
6
+ metadata.gz: 0a5a1c40d3df8b8edcde06aac1f1c7ed26f9015a6b04703325657b9f58957e2edfeaa92c91c29915acbc06a98f24a7a2b428f3b1496f56d5d885a51106361202
7
+ data.tar.gz: 16e2c959ccdc94dbe9250081f1567287f38223f9f368c145164f54f45fa53643ebd793bd985f7fefb48962749945e88a428bd9a6de40ddd63d41585da4f1f1af
@@ -0,0 +1,69 @@
1
+ # Parses Debian control files
2
+ class DebianControlParser
3
+ # Creates a new parser instance from either a file-like
4
+ # object or a string of multiple lines containing a
5
+ # Debian control file like Packages or Release.
6
+ #
7
+ # @param data [File,String] the object to read lines from (e.g. a multiline-string or a file)
8
+ # @return [DebianControlParser] a parser instance
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ # Iterator that returns fields from the input data. If the file
14
+ # consists of several paragraphs (seperated by empty lines)
15
+ # it must first be split by using the 'paragraphs' iterator.
16
+ #
17
+ # yield [Array<String,String>] a name/value pair for each field
18
+ def fields
19
+ return enum_for(:each) unless block_given?
20
+
21
+ name=value=''
22
+ @data.each_line do |line|
23
+ case line
24
+ when /^(.+): (.+)/ # "Key: Value"
25
+ yield(name,value) unless value.empty?
26
+ name,value=$1,$2
27
+ when /^(.+):\s*/ # "Key:" (start of multi-line entry)
28
+ yield(name,value) unless value.empty?
29
+ name=$1
30
+ value=''
31
+ when /^\s+(.+)/ # " Indented multi-line value"
32
+ value << $1+"\n"
33
+ when /^\s+$/ # Empty line
34
+ break
35
+ end
36
+ end
37
+
38
+ # Any lines left at the end of the input?
39
+ yield(name,value) unless value.empty?
40
+ end
41
+
42
+ # Iterator that splits up the input of a debian control file
43
+ # by empty lines. For example Debian "Packages" files consist
44
+ # of one paragraph for each package listed in it.
45
+ #
46
+ # @yield [DebianControlParser] a parser instance that you can use .fields on
47
+ def paragraphs
48
+ return enum_for(:each) unless block_given?
49
+
50
+ gathered_lines = '' # collects all lines belonging to a field
51
+ @data.each_line do |line|
52
+ if line.chomp.empty? # empty line found that seperates paragraphs
53
+ unless gathered_lines.empty? # any lines gathered so far?
54
+ #yield gathered_lines # return the paragraph
55
+ yield DebianControlParser.new(gathered_lines)
56
+ gathered_lines = ''
57
+ end
58
+ else
59
+ gathered_lines << line
60
+ end
61
+ end
62
+
63
+ # Any lines left after the last empty line and the end of the input?
64
+ unless gathered_lines.empty?
65
+ #yield gathered_lines
66
+ yield DebianControlParser.new(gathered_lines)
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debian-control-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Haas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ description: |2
42
+ Iterates over Debian control files. As control files can be very
43
+ large this gem provides iterators for each block and each pair of
44
+ key/values in the file.
45
+ email: email@christoph-haas.de
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - lib/debian_control_parser.rb
51
+ homepage: http://github.com/Signum/debian-control-parser-gem
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.4.1
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Parses Debian control files
75
+ test_files: []
76
+ has_rdoc: