Skip to content

Commit 7c048a9

Browse files
committed
Move #start_with from URI to Value and add specs.
1 parent c930381 commit 7c048a9

4 files changed

Lines changed: 27 additions & 16 deletions

File tree

lib/rdf/model/uri.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -673,22 +673,6 @@ def freeze
673673
self
674674
end
675675

676-
##
677-
# Returns `true` if this URI starts with the given `string`.
678-
#
679-
# @example
680-
# RDF::URI('http://example.org/').start_with?('http') #=> true
681-
# RDF::URI('http://example.org/').start_with?('ftp') #=> false
682-
#
683-
# @param [String, #to_s] string
684-
# @return [Boolean] `true` or `false`
685-
# @see String#start_with?
686-
# @since 0.3.0
687-
def start_with?(string)
688-
to_s.start_with?(string.to_s)
689-
end
690-
alias_method :starts_with?, :start_with?
691-
692676
##
693677
# Returns `true` if this URI ends with the given `string`.
694678
#

lib/rdf/model/value.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ def validate!
159159
end
160160
alias_method :validate, :validate!
161161

162+
##
163+
# Returns `true` if this Value starts with the given `string`.
164+
#
165+
# @example
166+
# RDF::URI('http://example.org/').start_with?('http') #=> true
167+
# RDF::Node('_:foo').start_with?('_:bar') #=> false
168+
# RDF::Litera('Apple').start_with?('Orange') #=> false
169+
#
170+
# @param [String, #to_s] string
171+
# @return [Boolean] `true` or `false`
172+
# @see String#start_with?
173+
# @since 0.3.0
174+
def start_with?(string)
175+
to_s.start_with?(string.to_s)
176+
end
177+
alias_method :starts_with?, :start_with?
178+
162179
##
163180
# Returns a copy of this value converted into its canonical
164181
# representation.

spec/model_literal_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def self.literals(*selector)
155155
end
156156
end
157157

158+
it "#start_with?" do
159+
expect(RDF::Literal('foo')).to be_start_with('foo')
160+
expect(RDF::Literal('bar')).not_to be_start_with('foo')
161+
end
162+
158163
describe "#==" do
159164
literals(:all_plain).each do |args|
160165
it "returns true for #{args.inspect}" do

spec/model_node_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
specify {expect(RDF::Node.intern(:a)).to eql RDF::Node.intern("a")}
5757
end
5858

59+
it "#start_with?" do
60+
expect(RDF::Node('foo')).to be_start_with('_:foo')
61+
expect(RDF::Node('bar')).not_to be_start_with('_:foo')
62+
end
63+
5964
subject {new.call("foo")}
6065

6166
describe "#dup" do

0 commit comments

Comments
 (0)