sxp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/AUTHORS +2 -1
  2. data/VERSION +1 -1
  3. data/lib/sxp/reader.rb +47 -20
  4. data/lib/sxp/version.rb +13 -4
  5. metadata +38 -12
  6. data/Rakefile +0 -8
data/AUTHORS CHANGED
@@ -1 +1,2 @@
1
- * Arto Bendiken <arto.bendiken@gmail.com> (Lead developer)
1
+ * Arto Bendiken <arto.bendiken@gmail.com>
2
+ * Ben Lavender <blavender@gmail.com>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/sxp/reader.rb CHANGED
@@ -1,29 +1,54 @@
1
1
  module SXP
2
-
3
- # Reads one S-expression from the given input stream.
4
- def self.read(input)
5
- Reader.new(input).read
6
- end
7
-
8
- # Reads all S-expressions from the given input stream.
9
- def self.read_all(input)
10
- Reader.new(input).read_all
2
+ ##
3
+ # Reads all S-expressions from a given input URI using the HTTP or FTP
4
+ # protocols.
5
+ #
6
+ # @param [String, #to_s] url
7
+ # @param [Hash{Symbol => Object}] options
8
+ # @return [Enumerable<Object>]
9
+ def self.read_url(url, options = {})
10
+ require 'openuri'
11
+ open(url.to_s, 'rb', nil, options) { |io| read_all(io, options) }
11
12
  end
12
13
 
14
+ ##
13
15
  # Reads all S-expressions from the given input files.
16
+ #
17
+ # @param [Enumerable<String>] filenames
18
+ # @param [Hash{Symbol => Object}] options
19
+ # @return [Enumerable<Object>]
14
20
  def self.read_files(*filenames)
15
- filenames.map { |filename| read_file(filename) }.inject { |sxps, sxp| sxps + sxp }
21
+ filenames.map { |filename| read_file(filename, options) }.inject { |sxps, sxp| sxps + sxp }
16
22
  end
17
23
 
24
+ ##
18
25
  # Reads all S-expressions from a given input file.
19
- def self.read_file(filename)
20
- File.open(filename, 'rb') { |io| read_all(io) }
26
+ #
27
+ # @param [String, #to_s] filename
28
+ # @param [Hash{Symbol => Object}] options
29
+ # @return [Enumerable<Object>]
30
+ def self.read_file(filename, options = {})
31
+ File.open(filename.to_s, 'rb') { |io| read_all(io, options) }
21
32
  end
22
33
 
23
- # Reads all S-expressions from a given input URI using the HTTP or FTP protocols.
24
- def self.read_uri(uri, options = {})
25
- require 'openuri'
26
- open(uri, 'rb', nil, options) { |io| read_all(io) }
34
+ ##
35
+ # Reads all S-expressions from the given input stream.
36
+ #
37
+ # @param [IO, StringIO, String] input
38
+ # @param [Hash{Symbol => Object}] options
39
+ # @return [Enumerable<Object>]
40
+ def self.read_all(input, options = {})
41
+ Reader.new(input, options).read_all
42
+ end
43
+
44
+ ##
45
+ # Reads one S-expression from the given input stream.
46
+ #
47
+ # @param [IO, StringIO, String] input
48
+ # @param [Hash{Symbol => Object}] options
49
+ # @return [Object]
50
+ def self.read(input, options = {})
51
+ Reader.new(input, options).read
27
52
  end
28
53
 
29
54
  class << self
@@ -31,7 +56,9 @@ module SXP
31
56
  alias_method :parse_all, :read_all
32
57
  alias_method :parse_files, :read_files
33
58
  alias_method :parse_file, :read_file
34
- alias_method :parse_uri, :read_uri
59
+ alias_method :parse_url, :read_url
60
+ alias_method :parse_uri, :read_url # @deprecated
61
+ alias_method :read_uri, :read_url # @deprecated
35
62
  end
36
63
 
37
64
  class Reader
@@ -40,7 +67,7 @@ module SXP
40
67
  class Error < StandardError; end
41
68
  class EOF < Error; end
42
69
 
43
- FLOAT = /^[+-]?(?:\d+)?\.\d*$/
70
+ FLOAT = /^[+-]?(\d*)?\.\d*$/
44
71
  INTEGER_BASE_2 = /^[+-]?[01]+$/
45
72
  INTEGER_BASE_8 = /^[+-]?[0-7]+$/
46
73
  INTEGER_BASE_10 = /^[+-]?\d+$/
@@ -50,7 +77,7 @@ module SXP
50
77
 
51
78
  attr_reader :input
52
79
 
53
- def initialize(input)
80
+ def initialize(input, options = {})
54
81
  case
55
82
  when [:getc, :ungetc, :eof?].all? { |x| input.respond_to?(x) }
56
83
  @input = input
@@ -68,7 +95,7 @@ module SXP
68
95
 
69
96
  def read_all(options = {})
70
97
  list = []
71
- catch (:eof) { list << read(:eof => :throw, *options) until eof? }
98
+ catch (:eof) { list << read(options.merge(:eof => :throw)) until eof? }
72
99
  list
73
100
  end
74
101
 
data/lib/sxp/version.rb CHANGED
@@ -1,14 +1,23 @@
1
1
  module SXP
2
- module VERSION #:nodoc:
2
+ module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
- STRING << "-#{EXTRA}" if EXTRA
9
+ STRING << ".#{EXTRA}" if EXTRA
10
10
 
11
- def self.to_s() STRING end
11
+ ##
12
+ # @return [String]
13
+ def self.to_s() STRING end
14
+
15
+ ##
16
+ # @return [String]
12
17
  def self.to_str() STRING end
18
+
19
+ ##
20
+ # @return [Array(Integer, Integer, Integer)]
21
+ def self.to_a() [MAJOR, MINOR, TINY] end
13
22
  end
14
23
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sxp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Arto Bendiken
@@ -9,24 +14,42 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-21 00:00:00 +01:00
13
- default_executable: sxp2json
17
+ date: 2010-05-13 00:00:00 +02:00
18
+ default_executable: sxp2rdf
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ - 0
31
+ version: 1.3.0
17
32
  type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: yard
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
20
38
  requirements:
21
39
  - - ">="
22
40
  - !ruby/object:Gem::Version
23
- version: 1.2.9
24
- version:
41
+ segments:
42
+ - 0
43
+ - 5
44
+ - 4
45
+ version: 0.5.4
46
+ type: :development
47
+ version_requirements: *id002
25
48
  description: " SXP is a data interchange format based on S-expressions, the simplest and\n most versatile known means of representing complex data structures such as\n lists, trees and graphs.\n"
26
49
  email: arto.bendiken@gmail.com
27
50
  executables:
28
- - sxp2json
29
51
  - sxp2rdf
52
+ - sxp2json
30
53
  - sxp2xml
31
54
  - sxp2yaml
32
55
  extensions: []
@@ -36,7 +59,6 @@ extra_rdoc_files: []
36
59
  files:
37
60
  - AUTHORS
38
61
  - README
39
- - Rakefile
40
62
  - UNLICENSE
41
63
  - VERSION
42
64
  - lib/sxp/extensions.rb
@@ -60,18 +82,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
82
  requirements:
61
83
  - - ">="
62
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 1
87
+ - 8
88
+ - 2
63
89
  version: 1.8.2
64
- version:
65
90
  required_rubygems_version: !ruby/object:Gem::Requirement
66
91
  requirements:
67
92
  - - ">="
68
93
  - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
69
96
  version: "0"
70
- version:
71
97
  requirements: []
72
98
 
73
99
  rubyforge_project: sxp
74
- rubygems_version: 1.3.5
100
+ rubygems_version: 1.3.6
75
101
  signing_key:
76
102
  specification_version: 3
77
103
  summary: A pure-Ruby implementation of the SXP data interchange format.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
3
- require 'rubygems'
4
- begin
5
- require 'rakefile' # http://github.com/bendiken/rakefile
6
- rescue LoadError => e
7
- end
8
- require 'sxp'