obo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,72 +4,43 @@ require_relative 'stanza'
4
4
  module Obo
5
5
  class Parser
6
6
  STANZA_START = /^\[(.*?)\]/
7
- TAG_VALUE = /^(.*?):([^!]*)/
7
+ TAG_VALUE = /^(.*?):\s*([^!]*)\n/
8
8
 
9
9
  def initialize(filename)
10
- @header = nil
11
- @io = File.open(filename)
10
+ @io = File.open(filename)
12
11
  end
13
12
 
14
13
  def elements(io = @io)
15
14
  Enumerator.new do |yielder|
16
- header = Header.new
17
- prev_line_position = io.pos
18
- line = lines.next
19
-
20
- until line.is_a? Stanza
21
- header.add(*line)
22
- prev_line_position = io.pos
23
- line = lines.next
15
+ header = Header.new
16
+ while io.gets.match TAG_VALUE
17
+ header.add($1, $2)
24
18
  end
25
19
 
26
20
  yielder << header
27
- io.pos = prev_line_position
28
21
 
29
- stanzas.each { |stanza| yielder << stanza }
30
- end
31
- end
22
+ io.gets until $_.match(STANZA_START)
23
+ stanza = Stanza.new($1.strip)
32
24
 
33
- def rewind(io = @io)
34
- io.pos = 0
35
- end
36
-
37
- private
38
-
39
- def stanzas
40
- Enumerator.new do |yielder|
41
- stanza = lines.first { |line| line.is_a? Stanza }
42
-
43
- begin
44
- while line = lines.next
45
- case line
46
- when Array
47
- stanza.add(*line)
48
- when Stanza
49
- yielder << stanza
50
- stanza = line
51
- end
25
+ while io.gets
26
+ case $_
27
+ when TAG_VALUE
28
+ stanza.add($1, $2)
29
+ when STANZA_START
30
+ yielder << stanza
31
+ stanza = Stanza.new($1.strip)
52
32
  end
53
- rescue StopIteration
54
- yielder << stanza
55
33
  end
56
34
 
35
+ yielder << stanza
36
+ rewind
57
37
  end
58
38
  end
59
39
 
60
- # Yields lines that are either Stanza name or tag-value pairs
61
- def lines(io = @io)
62
- Enumerator.new do |yielder|
63
- while line = io.gets
64
- case line.strip
65
- when STANZA_START
66
- yielder << Stanza.new($1.strip)
67
- when TAG_VALUE
68
- yielder << [$1.strip,$2.strip]
69
- end
70
- end
71
- end
40
+ def rewind(io = @io)
41
+ io.pos = 0
72
42
  end
43
+
73
44
  end
74
45
  end
75
46
 
@@ -1,3 +1,3 @@
1
1
  module Obo
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -4,7 +4,6 @@ require "pp"
4
4
  class TestObo < MiniTest::Unit::TestCase
5
5
  def setup
6
6
  @obo = Obo::Parser.new('test/data/ro.obo')
7
- # @obo = Obo::Parser.new('test/data/so_2_4_3.obo')
8
7
  end
9
8
 
10
9
  def test_header_parsing
@@ -50,8 +49,6 @@ class TestObo < MiniTest::Unit::TestCase
50
49
  def test_rewind
51
50
  # Run through the file to the end
52
51
  @obo.elements.count
53
- assert_raises(StopIteration){@obo.elements.count}
54
- @obo.rewind
55
52
  assert_equal 27, @obo.elements.count
56
53
  end
57
54
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Robert Syme
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-05-03 00:00:00.000000000 Z
13
+ date: 2013-06-25 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ~>
19
21
  - !ruby/object:Gem::Version
@@ -21,11 +23,12 @@ dependencies:
21
23
  type: :development
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ~>
26
29
  - !ruby/object:Gem::Version
27
30
  version: '1.3'
28
- description: 'The OBO format is the text file format used by OBO-Edit, the open-source,
31
+ description: ! 'The OBO format is the text file format used by OBO-Edit, the open-source,
29
32
  platform-independent application for viewing and editing ontologies. The format
30
33
  is described here: http://www.geneontology.org/GO.format.obo-1_2.shtml'
31
34
  email:
@@ -57,26 +60,33 @@ files:
57
60
  homepage: http://github.com/robsyme/obo
58
61
  licenses:
59
62
  - MIT
60
- metadata: {}
61
63
  post_install_message:
62
64
  rdoc_options: []
63
65
  require_paths:
64
66
  - lib
65
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
66
69
  requirements:
67
- - - '>='
70
+ - - ! '>='
68
71
  - !ruby/object:Gem::Version
69
72
  version: '0'
73
+ segments:
74
+ - 0
75
+ hash: 2033594933957096070
70
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
71
78
  requirements:
72
- - - '>='
79
+ - - ! '>='
73
80
  - !ruby/object:Gem::Version
74
81
  version: '0'
82
+ segments:
83
+ - 0
84
+ hash: 2033594933957096070
75
85
  requirements: []
76
86
  rubyforge_project:
77
- rubygems_version: 2.0.0.rc.2
87
+ rubygems_version: 1.8.24
78
88
  signing_key:
79
- specification_version: 4
89
+ specification_version: 3
80
90
  summary: A parser for the OBO flat file format
81
91
  test_files:
82
92
  - test/data/ro.obo
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 179add8eb74e998aa0db59d8aa58520648d56995
4
- data.tar.gz: 94d64cb521380eeb3fb394bb42f8dba46c81497a
5
- SHA512:
6
- metadata.gz: f7495d695a3c85947b3504a12965ec58b8fb8d4307aefa02263129b8580611d7f3f914d62a478e7d4185a2543fe16ff09061464e018783ea305e781e2c9eb714
7
- data.tar.gz: ab6ec0e629f33b10df673301eb721502be9857dc99362a7551a742819fa4d69874cc794eabe354d00682b237c88c5082652c1e20c7256856b019961275b28c08