Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add valid methods #101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/barby/barcode/bookland.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Barby
#
# If a prefix is not given, a default of 978 is used.
class Bookland < EAN13
attr_accessor :isbn

# isbn should be an ISBN number string, with or without an EAN prefix and an ISBN checksum
# non-number formatting like hyphens or spaces are ignored
Expand Down Expand Up @@ -61,12 +62,11 @@ def initialize(isbn)


def isbn=(isbn)
if match = PATTERN.match(isbn.gsub(/\D/, ''))
@number = match[:number]
@prefix = match[:prefix]
else
raise ArgumentError, "Not a valid ISBN: #{isbn}"
end
raise ArgumentError, "Not a valid ISBN: #{isbn}" if valid?

match = PATTERN.match(isbn.gsub(/\D/, ''))
@number = match[:number]
@prefix = match[:prefix]
end

def isbn
Expand Down Expand Up @@ -135,9 +135,15 @@ def inspect
"#<#{self.class}:0x#{'%014x' % object_id} #{formatted_isbn}>"
end

def valid?
!!PATTERN.match(isbn.gsub(/\D/, ''))
end

end#class ISBN

def valid?
!!ISBN::PATTERN.match(isbn.gsub(/\D/, ''))
end

end#class Bookland

Expand Down
4 changes: 4 additions & 0 deletions lib/barby/barcode/code_25_iata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def stop_encoding
encoding_for_bars_without_end_space(STOP_ENCODING)
end

def valid?
!!data
end

end

end
3 changes: 3 additions & 0 deletions lib/barby/barcode/data_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def to_s
end


def valid?
!!data
end
end

end
1 change: 0 additions & 1 deletion lib/barby/barcode/gs1_128.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def to_s
"(#{application_identifier}) #{partial_data}"
end


end


Expand Down
6 changes: 6 additions & 0 deletions lib/barby/barcode/pdf_417.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

module Barby
class Pdf417 < Barcode2D
attr_reader :data

DEFAULT_OPTIONS = {
:options => 0,
:y_height => 3,
Expand Down Expand Up @@ -72,5 +74,9 @@ def encoding
end
enc
end

def valid?
!!data
end
end
end
4 changes: 4 additions & 0 deletions lib/barby/barcode/qr_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def to_s
end


def valid?
!!data
end

private

#Generate an RQRCode object with the available values
Expand Down
3 changes: 3 additions & 0 deletions test/code_25_iata_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ class Code25IATATest < Barby::TestCase
@code.stop_encoding.must_equal '11101'
end

it "should be valid" do
@code.valid?.must_equal true
end
end
3 changes: 3 additions & 0 deletions test/data_matrix_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ class DataMatrixTest < Barby::TestCase
@code.encoding.wont_equal prev_encoding
end

it "should be valid" do
@code.valid?.must_equal true
end
end
4 changes: 4 additions & 0 deletions test/pdf_417_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Pdf417Test < Barby::TestCase
enc[0].length.must_equal 117
end

it "should be valid" do
@code.valid?.must_equal true
end

end

end
5 changes: 4 additions & 1 deletion test/qr_code_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class QrCodeTest < Barby::TestCase
QrCode.new('123456789012345678901234567890').to_s.must_equal '12345678901234567890'
end


it "should be valid" do
@code.valid?.must_equal true
end

private

def rqrcode(code)
Expand Down