ruby-nuggets 0.9.8.1 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +1 -1
- data/Rakefile +9 -3
- data/lib/nuggets/all.rb +1 -1
- data/lib/nuggets/array/combination.rb +2 -25
- data/lib/nuggets/array/flatten_once.rb +1 -12
- data/lib/nuggets/array/format.rb +2 -60
- data/lib/nuggets/array/in_order.rb +1 -12
- data/lib/nuggets/array/monotone.rb +10 -27
- data/lib/nuggets/array/only.rb +1 -16
- data/lib/nuggets/array/shuffle.rb +1 -1
- data/lib/nuggets/array/to_hash.rb +1 -22
- data/lib/nuggets/cli.rb +2 -2
- data/lib/nuggets/content_type.rb +3 -8
- data/lib/nuggets/dotted_decimal.rb +0 -18
- data/lib/nuggets/enumerable/all_any_extended.rb +0 -27
- data/lib/nuggets/enumerable/minmax.rb +4 -25
- data/lib/nuggets/hash/at.rb +2 -20
- data/lib/nuggets/hash/deep_fetch.rb +5 -0
- data/lib/nuggets/hash/deep_fetch_mixin.rb +75 -0
- data/lib/nuggets/hash/in_order.rb +0 -8
- data/lib/nuggets/hash/insert.rb +2 -13
- data/lib/nuggets/hash/only.rb +2 -18
- data/lib/nuggets/i18n.rb +1 -10
- data/lib/nuggets/integer/factorial.rb +0 -17
- data/lib/nuggets/integer/to_binary_s.rb +0 -8
- data/lib/nuggets/lsi.rb +2 -2
- data/lib/nuggets/midos.rb +2 -2
- data/lib/nuggets/mysql.rb +6 -207
- data/lib/nuggets/numeric/duration.rb +0 -8
- data/lib/nuggets/numeric/limit.rb +1 -8
- data/lib/nuggets/numeric/signum.rb +0 -7
- data/lib/nuggets/numeric/to_multiple.rb +0 -6
- data/lib/nuggets/rdf/compression.rb +3 -89
- data/lib/nuggets/rdf/prefix.rb +6 -32
- data/lib/nuggets/rdf/turtle/reader.rb +5 -70
- data/lib/nuggets/rdf/turtle.rb +6 -122
- data/lib/nuggets/rdf/uri.rb +5 -37
- data/lib/nuggets/ruby.rb +39 -147
- data/lib/nuggets/string/capitalize_first.rb +2 -18
- data/lib/nuggets/string/case.rb +0 -22
- data/lib/nuggets/string/msub.rb +0 -18
- data/lib/nuggets/string/nsub.rb +2 -16
- data/lib/nuggets/string/sub_with_md.rb +6 -25
- data/lib/nuggets/string/word_wrap.rb +1 -35
- data/lib/nuggets/util/ansicolor2css.rb +1 -1
- data/lib/nuggets/util/cli.rb +1 -1
- data/lib/nuggets/util/content_type.rb +1 -1
- data/lib/nuggets/util/dotted_decimal.rb +1 -2
- data/lib/nuggets/util/i18n.rb +1 -1
- data/lib/nuggets/util/lazy_attr.rb +1 -1
- data/lib/nuggets/util/log_parser/apache.rb +1 -1
- data/lib/nuggets/util/log_parser/rails.rb +1 -1
- data/lib/nuggets/util/log_parser.rb +1 -1
- data/lib/nuggets/util/midos.rb +1 -1
- data/lib/nuggets/util/mysql.rb +1 -1
- data/lib/nuggets/util/pluggable.rb +1 -1
- data/lib/nuggets/util/ruby.rb +1 -1
- data/lib/nuggets/version.rb +2 -2
- data/spec/nuggets/array/boost_spec.rb +1 -3
- data/spec/nuggets/array/combination_spec.rb +25 -0
- data/spec/nuggets/array/correlation_spec.rb +1 -3
- data/spec/nuggets/array/flatten_once_spec.rb +16 -0
- data/spec/nuggets/array/flush_spec.rb +1 -3
- data/spec/nuggets/array/format_spec.rb +52 -0
- data/spec/nuggets/array/hashify_spec.rb +1 -3
- data/spec/nuggets/array/histogram_spec.rb +1 -3
- data/spec/nuggets/array/in_order_spec.rb +13 -0
- data/spec/nuggets/array/limit_spec.rb +1 -3
- data/spec/nuggets/array/mean_spec.rb +3 -5
- data/spec/nuggets/array/median_spec.rb +3 -5
- data/spec/nuggets/array/mode_spec.rb +1 -3
- data/spec/nuggets/array/monotone_spec.rb +30 -0
- data/spec/nuggets/array/only_spec.rb +26 -0
- data/spec/nuggets/array/regression_spec.rb +1 -3
- data/spec/nuggets/array/runiq_spec.rb +1 -3
- data/spec/nuggets/array/standard_deviation_spec.rb +1 -3
- data/spec/nuggets/array/to_hash_spec.rb +28 -0
- data/spec/nuggets/array/variance_spec.rb +3 -5
- data/spec/nuggets/dotted_decimal_spec.rb +27 -0
- data/spec/nuggets/enumerable/all_any_extended_spec.rb +31 -0
- data/spec/nuggets/enumerable/minmax_spec.rb +21 -0
- data/spec/nuggets/env/set_spec.rb +1 -3
- data/spec/nuggets/env/user_encoding_spec.rb +1 -3
- data/spec/nuggets/env/user_home_spec.rb +12 -10
- data/spec/nuggets/file/ext_spec.rb +1 -3
- data/spec/nuggets/file/replace_spec.rb +1 -3
- data/spec/nuggets/file/sub_spec.rb +1 -3
- data/spec/nuggets/file/which_spec.rb +1 -3
- data/spec/nuggets/hash/at_spec.rb +19 -0
- data/spec/nuggets/hash/deep_fetch_spec.rb +159 -0
- data/spec/nuggets/hash/deep_merge_spec.rb +1 -3
- data/spec/nuggets/hash/in_order_spec.rb +12 -0
- data/spec/nuggets/hash/insert_spec.rb +13 -0
- data/spec/nuggets/hash/nest_spec.rb +1 -3
- data/spec/nuggets/hash/only_spec.rb +29 -0
- data/spec/nuggets/hash/seen_spec.rb +4 -6
- data/spec/nuggets/hash/unroll_spec.rb +2 -4
- data/spec/nuggets/i18n_spec.rb +13 -0
- data/spec/nuggets/integer/factorial_spec.rb +10 -0
- data/spec/nuggets/integer/length_spec.rb +1 -3
- data/spec/nuggets/integer/map_spec.rb +1 -3
- data/spec/nuggets/integer/to_binary_s_spec.rb +19 -0
- data/spec/nuggets/numeric/duration_spec.rb +25 -0
- data/spec/nuggets/numeric/limit_spec.rb +16 -0
- data/spec/nuggets/numeric/signum_spec.rb +16 -0
- data/spec/nuggets/numeric/to_multiple_spec.rb +16 -0
- data/spec/nuggets/object/blank_spec.rb +1 -2
- data/spec/nuggets/object/boolean_spec.rb +1 -3
- data/spec/nuggets/object/msend_spec.rb +1 -3
- data/spec/nuggets/object/silence_spec.rb +7 -4
- data/spec/nuggets/object/singleton_class_spec.rb +11 -4
- data/spec/nuggets/proc/bind_spec.rb +1 -3
- data/spec/nuggets/range/quantile_spec.rb +1 -3
- data/spec/nuggets/string/camelscore_spec.rb +11 -13
- data/spec/nuggets/string/capitalize_first_spec.rb +13 -0
- data/spec/nuggets/string/case_spec.rb +31 -0
- data/spec/nuggets/string/evaluate_spec.rb +1 -3
- data/spec/nuggets/string/msub_spec.rb +20 -0
- data/spec/nuggets/string/nsub_spec.rb +13 -0
- data/spec/nuggets/string/sub_with_md_spec.rb +25 -0
- data/spec/nuggets/string/wc_spec.rb +1 -3
- data/spec/nuggets/string/word_wrap_spec.rb +81 -0
- data/spec/nuggets/string/xor_spec.rb +1 -3
- data/spec/nuggets/uri/content_type_spec.rb +32 -27
- data/spec/nuggets/uri/exist_spec.rb +33 -9
- data/spec/spec_helper.rb +17 -0
- metadata +34 -5
- data/.rspec +0 -1
@@ -55,20 +55,3 @@ class Integer
|
|
55
55
|
alias_method :f!, :factorial
|
56
56
|
|
57
57
|
end
|
58
|
-
|
59
|
-
if $0 == __FILE__
|
60
|
-
1.upto(8) { |i|
|
61
|
-
puts "#{i}: #{i.factorial}"
|
62
|
-
}
|
63
|
-
|
64
|
-
require 'benchmark'
|
65
|
-
|
66
|
-
::Benchmark.bm(19) { |x|
|
67
|
-
[20000, 800, 300, 700, 130, 480, 9999, 9999, 25000].each { |i|
|
68
|
-
puts "#{i}:"
|
69
|
-
|
70
|
-
x.report('factorial') { i.factorial }
|
71
|
-
x.report('factorial_memoized') { i.factorial_memoized }
|
72
|
-
}
|
73
|
-
}
|
74
|
-
end
|
data/lib/nuggets/lsi.rb
CHANGED
@@ -2,7 +2,7 @@ begin
|
|
2
2
|
require 'lsi4r'
|
3
3
|
module Nuggets; LSI = ::Lsi4R; end
|
4
4
|
|
5
|
-
warn "#{__FILE__}: Nuggets::LSI is deprecated, use Lsi4R instead."
|
5
|
+
warn "#{__FILE__}: Nuggets::LSI is deprecated, use Lsi4R instead." unless ENV['NUGGETS_DEPRECATED_LSI']
|
6
6
|
rescue LoadError => err
|
7
|
-
warn "#{__FILE__}: Nuggets::LSI is no longer available; install `lsi4r' instead. (#{err})"
|
7
|
+
warn "#{__FILE__}: Nuggets::LSI is no longer available; install `lsi4r' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_LSI']
|
8
8
|
end
|
data/lib/nuggets/midos.rb
CHANGED
@@ -2,7 +2,7 @@ begin
|
|
2
2
|
require 'midos'
|
3
3
|
module Nuggets; Midos = ::Midos; end
|
4
4
|
|
5
|
-
warn "#{__FILE__}: Nuggets::Midos is deprecated, use Midos instead."
|
5
|
+
warn "#{__FILE__}: Nuggets::Midos is deprecated, use Midos instead." unless ENV['NUGGETS_DEPRECATED_MIDOS']
|
6
6
|
rescue LoadError => err
|
7
|
-
warn "#{__FILE__}: Nuggets::Midos is no longer available; install `midos' instead. (#{err})"
|
7
|
+
warn "#{__FILE__}: Nuggets::Midos is no longer available; install `midos' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_MIDOS']
|
8
8
|
end
|
data/lib/nuggets/mysql.rb
CHANGED
@@ -1,209 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2013 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
1
|
+
begin
|
2
|
+
require 'mysql_parser'
|
3
|
+
module Nuggets; module MySQL; Parser = ::MysqlParser; end; end
|
27
4
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
module MySQL
|
32
|
-
|
33
|
-
class Parser
|
34
|
-
|
35
|
-
DEFAULT_NAME = '__DEFAULT__'
|
36
|
-
DEFAULT_TABLE = '__DEFAULT__'
|
37
|
-
|
38
|
-
USE_RE = /\AUSE\s+`(.+?)`/i
|
39
|
-
CREATE_TABLE_RE = /\ACREATE\s+TABLE\s+`(.+?)`/i
|
40
|
-
TABLE_COLUMN_RE = /\A\s+`(.+?)`/
|
41
|
-
FINISH_TABLE_RE = /\A\).*;\Z/
|
42
|
-
INSERT_VALUES_RE = /\AINSERT\s+INTO\s+`(.+?)`\s+(?:\((.+?)\)\s+)?VALUES\s*(.*);\Z/i
|
43
|
-
CLEAN_COLUMNS_RE = /[\s`]+/
|
44
|
-
|
45
|
-
def self.parse(input, &block)
|
46
|
-
parser = new.parse(input, &block)
|
47
|
-
block_given? ? parser : parser.tables
|
48
|
-
end
|
49
|
-
|
50
|
-
def initialize
|
51
|
-
reset
|
52
|
-
end
|
53
|
-
|
54
|
-
def reset
|
55
|
-
@name = DEFAULT_NAME
|
56
|
-
@table = DEFAULT_TABLE
|
57
|
-
@tables = {}
|
58
|
-
@columns = Hash.new { |h, k| h[k] = [] }
|
59
|
-
@value_parser = ValueParser.new
|
60
|
-
end
|
61
|
-
|
62
|
-
attr_reader :tables
|
63
|
-
|
64
|
-
def parse(input, &block)
|
65
|
-
unless block
|
66
|
-
tables, block = @tables, lambda { |_, name, table, columns, values|
|
67
|
-
((tables[name] ||= {})[table] ||= []) << fields = {}
|
68
|
-
|
69
|
-
values.each_with_index { |value, index|
|
70
|
-
if column = columns[index]
|
71
|
-
fields[column] = value
|
72
|
-
end
|
73
|
-
}
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
name, table, columns, value_parser, block_given =
|
78
|
-
@name, @table, @columns, @value_parser, block_given?
|
79
|
-
|
80
|
-
input.each { |line|
|
81
|
-
case line
|
82
|
-
when USE_RE
|
83
|
-
name = $1
|
84
|
-
yield :use, name if block_given
|
85
|
-
when CREATE_TABLE_RE
|
86
|
-
table = $1
|
87
|
-
when TABLE_COLUMN_RE
|
88
|
-
columns[table] << $1 if table
|
89
|
-
when FINISH_TABLE_RE
|
90
|
-
yield :table, name, table, columns[table] if block_given
|
91
|
-
table = nil
|
92
|
-
when INSERT_VALUES_RE
|
93
|
-
_table, _columns, _values = $1, $2, $3
|
94
|
-
|
95
|
-
_columns = _columns.nil? ? columns[_table] :
|
96
|
-
_columns.gsub(CLEAN_COLUMNS_RE, '').split(',')
|
97
|
-
|
98
|
-
value_parser.parse(_values) { |values|
|
99
|
-
block[:insert, name, _table, _columns, values]
|
100
|
-
} unless _columns.empty?
|
101
|
-
end
|
102
|
-
}
|
103
|
-
|
104
|
-
@name, @table = name, table
|
105
|
-
|
106
|
-
self
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
class ValueParser
|
112
|
-
|
113
|
-
AST = Struct.new(:value)
|
114
|
-
|
115
|
-
def self.parse(input)
|
116
|
-
new.parse(input)
|
117
|
-
end
|
118
|
-
|
119
|
-
def parse(input)
|
120
|
-
@input = StringScanner.new(input)
|
121
|
-
|
122
|
-
rows, block_given = [], block_given?
|
123
|
-
|
124
|
-
while result = parse_row
|
125
|
-
row = result.value
|
126
|
-
block_given ? yield(row) : rows << row
|
127
|
-
break unless @input.scan(/,\s*/)
|
128
|
-
end
|
129
|
-
|
130
|
-
@input.scan(/;/) # optional
|
131
|
-
|
132
|
-
error('Unexpected data') unless @input.eos?
|
133
|
-
|
134
|
-
rows unless block_given
|
135
|
-
end
|
136
|
-
|
137
|
-
def parse_row
|
138
|
-
return unless @input.scan(/\(/)
|
139
|
-
|
140
|
-
row = []
|
141
|
-
|
142
|
-
while result = parse_value
|
143
|
-
row << result.value
|
144
|
-
break unless @input.scan(/,\s*/)
|
145
|
-
end
|
146
|
-
|
147
|
-
error('Unclosed row') unless @input.scan(/\)/)
|
148
|
-
|
149
|
-
AST.new(row)
|
150
|
-
end
|
151
|
-
|
152
|
-
def parse_value
|
153
|
-
parse_string ||
|
154
|
-
parse_number ||
|
155
|
-
parse_keyword
|
156
|
-
end
|
157
|
-
|
158
|
-
def parse_string
|
159
|
-
return unless @input.scan(/'/)
|
160
|
-
|
161
|
-
string = ''
|
162
|
-
|
163
|
-
while contents = parse_string_content || parse_string_escape
|
164
|
-
string << contents.value
|
165
|
-
end
|
166
|
-
|
167
|
-
error('Unclosed string') unless @input.scan(/'/)
|
168
|
-
|
169
|
-
AST.new(string)
|
170
|
-
end
|
171
|
-
|
172
|
-
def parse_string_content
|
173
|
-
if @input.scan(/[^\\']+/)
|
174
|
-
AST.new(@input.matched)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def parse_string_escape
|
179
|
-
if @input.scan(/\\[abtnvfr]/)
|
180
|
-
AST.new(eval(%Q{"#{@input.matched}"}))
|
181
|
-
elsif @input.scan(/\\.|''/)
|
182
|
-
AST.new(@input.matched[-1, 1])
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def parse_number
|
187
|
-
if @input.scan(/-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/)
|
188
|
-
AST.new(eval(@input.matched))
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def parse_keyword
|
193
|
-
if @input.scan(/null/i)
|
194
|
-
AST.new(nil)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def error(message)
|
199
|
-
if @input.eos?
|
200
|
-
raise "Unexpected end of input (#{message})."
|
201
|
-
else
|
202
|
-
raise "#{message} at #{$.}:#{@input.pos}: #{@input.peek(16).inspect}"
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
5
|
+
warn "#{__FILE__}: Nuggets::MySQL::Parser is deprecated, use MysqlParser instead." unless ENV['NUGGETS_DEPRECATED_MYSQL']
|
6
|
+
rescue LoadError => err
|
7
|
+
warn "#{__FILE__}: Nuggets::MySQL::Parser is no longer available; install `mysql_parser' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_MYSQL']
|
209
8
|
end
|
@@ -35,7 +35,7 @@ class Numeric
|
|
35
35
|
def limit(min, max)
|
36
36
|
min, max = max, min if max < min
|
37
37
|
|
38
|
-
|
38
|
+
min(min).max(max)
|
39
39
|
end
|
40
40
|
|
41
41
|
alias_method :between, :limit
|
@@ -61,10 +61,3 @@ class Numeric
|
|
61
61
|
alias_method :at_most, :max
|
62
62
|
|
63
63
|
end
|
64
|
-
|
65
|
-
if $0 == __FILE__
|
66
|
-
[123, -123, 0, 0.001, 1.23, -12.3].each { |n|
|
67
|
-
p n
|
68
|
-
p n.between(0, 10)
|
69
|
-
}
|
70
|
-
end
|
@@ -1,92 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
#--
|
4
|
-
###############################################################################
|
5
|
-
# #
|
6
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
7
|
-
# language. #
|
8
|
-
# #
|
9
|
-
# Copyright (C) 2007-2014 Jens Wille #
|
10
|
-
# #
|
11
|
-
# Authors: #
|
12
|
-
# Jens Wille <jens.wille@gmail.com> #
|
13
|
-
# #
|
14
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
15
|
-
# under the terms of the GNU Affero General Public License as published by #
|
16
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
17
|
-
# option) any later version. #
|
18
|
-
# #
|
19
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
20
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
21
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
22
|
-
# for more details. #
|
23
|
-
# #
|
24
|
-
# You should have received a copy of the GNU Affero General Public License #
|
25
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
26
|
-
# #
|
27
|
-
###############################################################################
|
28
|
-
#++
|
29
|
-
|
30
|
-
require 'rdf/util'
|
31
|
-
|
32
1
|
begin
|
33
|
-
require '
|
2
|
+
require 'turtle_reader/rdf/compression'
|
3
|
+
warn "#{__FILE__}: 'nuggets/rdf/compression' is deprecated, use 'turtle_reader/rdf/compression' instead." unless ENV['NUGGETS_DEPRECATED_RDF_COMPRESSION']
|
34
4
|
rescue LoadError => err
|
35
|
-
warn err
|
36
|
-
end
|
37
|
-
|
38
|
-
begin
|
39
|
-
require 'rbzip2'
|
40
|
-
|
41
|
-
class RBzip2::Decompressor
|
42
|
-
|
43
|
-
def eof?
|
44
|
-
@current_state == EOF
|
45
|
-
end
|
46
|
-
|
47
|
-
def gets(sep = $/)
|
48
|
-
r = ''
|
49
|
-
|
50
|
-
loop {
|
51
|
-
b = read0
|
52
|
-
break if b < 0
|
53
|
-
|
54
|
-
count(1)
|
55
|
-
r << b
|
56
|
-
|
57
|
-
break if r.end_with?(sep)
|
58
|
-
}
|
59
|
-
|
60
|
-
r
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
rescue LoadError => err
|
65
|
-
warn err if $VERBOSE
|
66
|
-
end
|
67
|
-
|
68
|
-
class << RDF::Util::File
|
69
|
-
|
70
|
-
alias_method :_nuggets_original_open_file, :open_file
|
71
|
-
|
72
|
-
def open_file(filename_or_url, options = {}, &block)
|
73
|
-
klass = begin
|
74
|
-
case File.extname(filename_or_url).downcase.sub(/\A\./, '')
|
75
|
-
when /\Abz(?:ip)?2?\z/ then RBzip2::Decompressor
|
76
|
-
when /\Agz(?:ip)?\z/ then Zlib::GzipReader
|
77
|
-
end
|
78
|
-
rescue NameError => err
|
79
|
-
err.message.sub!('Module::', '')
|
80
|
-
raise
|
81
|
-
end
|
82
|
-
|
83
|
-
if klass
|
84
|
-
original_block, block = block, lambda { |file|
|
85
|
-
original_block[file.is_a?(IO) ? klass.new(file) : file]
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
_nuggets_original_open_file(filename_or_url, options, &block)
|
90
|
-
end
|
91
|
-
|
5
|
+
warn "#{__FILE__}: 'nuggets/rdf/compression' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_COMPRESSION']
|
92
6
|
end
|
data/lib/nuggets/rdf/prefix.rb
CHANGED
@@ -1,32 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
# language. #
|
8
|
-
# #
|
9
|
-
# Copyright (C) 2007-2014 Jens Wille #
|
10
|
-
# #
|
11
|
-
# Authors: #
|
12
|
-
# Jens Wille <jens.wille@gmail.com> #
|
13
|
-
# #
|
14
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
15
|
-
# under the terms of the GNU Affero General Public License as published by #
|
16
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
17
|
-
# option) any later version. #
|
18
|
-
# #
|
19
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
20
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
21
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
22
|
-
# for more details. #
|
23
|
-
# #
|
24
|
-
# You should have received a copy of the GNU Affero General Public License #
|
25
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
26
|
-
# #
|
27
|
-
###############################################################################
|
28
|
-
#++
|
29
|
-
|
30
|
-
require 'rdf'
|
31
|
-
|
32
|
-
def RDF.__prefix__; :rdf; end
|
1
|
+
begin
|
2
|
+
require 'turtle_reader/rdf/prefix'
|
3
|
+
warn "#{__FILE__}: 'nuggets/rdf/prefix' is deprecated, use 'turtle_reader/rdf/prefix' instead." unless ENV['NUGGETS_DEPRECATED_RDF_PREFIX']
|
4
|
+
rescue LoadError => err
|
5
|
+
warn "#{__FILE__}: 'nuggets/rdf/prefix' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_PREFIX']
|
6
|
+
end
|
@@ -1,71 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
7
|
-
# language. #
|
8
|
-
# #
|
9
|
-
# Copyright (C) 2007-2014 Jens Wille #
|
10
|
-
# #
|
11
|
-
# Authors: #
|
12
|
-
# Jens Wille <jens.wille@gmail.com> #
|
13
|
-
# #
|
14
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
15
|
-
# under the terms of the GNU Affero General Public License as published by #
|
16
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
17
|
-
# option) any later version. #
|
18
|
-
# #
|
19
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
20
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
21
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
22
|
-
# for more details. #
|
23
|
-
# #
|
24
|
-
# You should have received a copy of the GNU Affero General Public License #
|
25
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
26
|
-
# #
|
27
|
-
###############################################################################
|
28
|
-
#++
|
29
|
-
|
30
|
-
require 'rdf/turtle'
|
31
|
-
|
32
|
-
module RDF
|
33
|
-
class Turtle::Reader
|
34
|
-
|
35
|
-
PARSE_OPTIONS = {
|
36
|
-
:branch => BRANCH,
|
37
|
-
:first => FIRST,
|
38
|
-
:follow => FOLLOW,
|
39
|
-
:reset_on_start => true
|
40
|
-
}
|
41
|
-
|
42
|
-
def closed?
|
43
|
-
@input.closed?
|
44
|
-
end
|
45
|
-
|
46
|
-
def parse_prologue
|
47
|
-
parse_internal { break }
|
48
|
-
rewind
|
49
|
-
[base_uri, prefixes]
|
50
|
-
end
|
51
|
-
|
52
|
-
def parse_statements
|
53
|
-
parse_internal { |context, _, *data|
|
54
|
-
if context == :statement
|
55
|
-
data[3] = { :context => data[3] }
|
56
|
-
yield Statement.new(*data)
|
57
|
-
end
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def parse_internal(&block)
|
64
|
-
parse(@input, START, @options.merge(PARSE_OPTIONS), &block)
|
65
|
-
rescue => err
|
66
|
-
err.message << " (line #{lineno})"
|
67
|
-
raise
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
1
|
+
begin
|
2
|
+
require 'turtle_reader/rdf/turtle/reader'
|
3
|
+
warn "#{__FILE__}: 'nuggets/rdf/turtle/reader' is deprecated, use 'turtle_reader/rdf/turtle/reader' instead." unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE_READER']
|
4
|
+
rescue LoadError => err
|
5
|
+
warn "#{__FILE__}: 'nuggets/rdf/turtle/reader' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE_READER']
|
71
6
|
end
|
data/lib/nuggets/rdf/turtle.rb
CHANGED
@@ -1,124 +1,8 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'turtle_reader'
|
3
|
+
module Nuggets; module RDF; Turtle = ::TurtleReader; end; end
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
7
|
-
# language. #
|
8
|
-
# #
|
9
|
-
# Copyright (C) 2007-2014 Jens Wille #
|
10
|
-
# #
|
11
|
-
# Authors: #
|
12
|
-
# Jens Wille <jens.wille@gmail.com> #
|
13
|
-
# #
|
14
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
15
|
-
# under the terms of the GNU Affero General Public License as published by #
|
16
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
17
|
-
# option) any later version. #
|
18
|
-
# #
|
19
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
20
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
21
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
22
|
-
# for more details. #
|
23
|
-
# #
|
24
|
-
# You should have received a copy of the GNU Affero General Public License #
|
25
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
26
|
-
# #
|
27
|
-
###############################################################################
|
28
|
-
#++
|
29
|
-
|
30
|
-
require 'nuggets/rdf/turtle/reader'
|
31
|
-
require 'nuggets/rdf/compression'
|
32
|
-
require 'nuggets/rdf/prefix'
|
33
|
-
require 'nuggets/rdf/uri'
|
34
|
-
|
35
|
-
module Nuggets
|
36
|
-
module RDF
|
37
|
-
class Turtle
|
38
|
-
|
39
|
-
include ::Enumerable
|
40
|
-
|
41
|
-
NS_SEPARATOR = ':'.freeze
|
42
|
-
|
43
|
-
NS = ::RDF::Vocabulary.inject({}) { |h, v| h[v.__prefix__] = v; h }
|
44
|
-
|
45
|
-
class << self
|
46
|
-
|
47
|
-
def open(file, *args)
|
48
|
-
::RDF::Reader.open(file, :format => :ttl) { |reader|
|
49
|
-
turtle = new(reader, *args)
|
50
|
-
turtle.file = ::File.expand_path(file)
|
51
|
-
|
52
|
-
return block_given? ? yield(turtle) : turtle
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def foreach(file, *args, &block)
|
57
|
-
open(file, *args) { |turtle| turtle.each(&block) }
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def initialize(reader, map = true)
|
63
|
-
@reader, @base, @prefixes = reader, *reader.parse_prologue
|
64
|
-
self.map = map
|
65
|
-
end
|
66
|
-
|
67
|
-
attr_reader :reader, :map, :base, :prefixes
|
68
|
-
|
69
|
-
attr_accessor :file
|
70
|
-
|
71
|
-
def map=(map)
|
72
|
-
unless map.is_a?(::Hash)
|
73
|
-
@map = ::Hash.new(map)
|
74
|
-
else
|
75
|
-
@map = {}
|
76
|
-
|
77
|
-
map.each { |k, v|
|
78
|
-
if k.is_a?(::String)
|
79
|
-
n, s = k.split(NS_SEPARATOR, 2)
|
80
|
-
k = NS.key?(n = n.to_sym) ? NS[n][s] : prefixes[n] / s
|
81
|
-
end
|
82
|
-
|
83
|
-
@map[k] = v
|
84
|
-
}
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def statements
|
89
|
-
each_statement.to_a
|
90
|
-
end
|
91
|
-
|
92
|
-
def each_statement(&block)
|
93
|
-
return enum_for(:each_statement) unless block_given?
|
94
|
-
reader.parse_statements(&block)
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
def each
|
99
|
-
return enum_for(:each) unless block_given?
|
100
|
-
|
101
|
-
uri, map, base = ::RDF::URI, self.map, self.base
|
102
|
-
|
103
|
-
each_statement { |t|
|
104
|
-
s, p, o = *t
|
105
|
-
|
106
|
-
if s.is_a?(uri) and k = map[p] and s.start_with?(base)
|
107
|
-
yield s, o, k
|
108
|
-
end
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
def closed?
|
113
|
-
reader.closed?
|
114
|
-
end
|
115
|
-
|
116
|
-
def inspect
|
117
|
-
'#<%s:0x%x @file=%p, @base=%p%s>' % [
|
118
|
-
self.class, object_id, file, base, closed? ? ' (closed)' : ''
|
119
|
-
]
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
end
|
5
|
+
warn "#{__FILE__}: Nuggets::RDF::Turtle is deprecated, use TurtleReader instead." unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE']
|
6
|
+
rescue LoadError => err
|
7
|
+
warn "#{__FILE__}: Nuggets::RDF::Turtle is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE']
|
124
8
|
end
|