Class: Bisac::POLineItem
- Inherits:
-
Object
- Object
- Bisac::POLineItem
- Defined in:
- lib/bisac/po_line_item.rb
Overview
represents a single line on the purchase order. Has attributes like price, qty and description
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#catalogue_code ⇒ Object
Returns the value of attribute catalogue_code.
-
#isbn ⇒ Object
Returns the value of attribute isbn.
-
#line_item_number ⇒ Object
Returns the value of attribute line_item_number.
-
#po_number ⇒ Object
Returns the value of attribute po_number.
-
#price ⇒ Object
Returns the value of attribute price.
-
#qty ⇒ Object
Returns the value of attribute qty.
-
#sequence_number ⇒ Object
Returns the value of attribute sequence_number.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.load_from_string(data) ⇒ Object
returns a new Bisac::POLineItem object using the data passed in as a string refer to the bisac spec for the expected format of the string.
Instance Method Summary collapse
- #isbn10 ⇒ Object
-
#isbn? ⇒ Boolean
is the isbn for this product valid?.
- #to_s ⇒ Object
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
11 12 13 |
# File 'lib/bisac/po_line_item.rb', line 11 def @author end |
#catalogue_code ⇒ Object
Returns the value of attribute catalogue_code.
10 11 12 |
# File 'lib/bisac/po_line_item.rb', line 10 def catalogue_code @catalogue_code end |
#isbn ⇒ Object
Returns the value of attribute isbn.
12 13 14 |
# File 'lib/bisac/po_line_item.rb', line 12 def isbn @isbn end |
#line_item_number ⇒ Object
Returns the value of attribute line_item_number.
9 10 11 |
# File 'lib/bisac/po_line_item.rb', line 9 def line_item_number @line_item_number end |
#po_number ⇒ Object
Returns the value of attribute po_number.
9 10 11 |
# File 'lib/bisac/po_line_item.rb', line 9 def po_number @po_number end |
#price ⇒ Object
Returns the value of attribute price.
10 11 12 |
# File 'lib/bisac/po_line_item.rb', line 10 def price @price end |
#qty ⇒ Object
Returns the value of attribute qty.
10 11 12 |
# File 'lib/bisac/po_line_item.rb', line 10 def qty @qty end |
#sequence_number ⇒ Object
Returns the value of attribute sequence_number.
9 10 11 |
# File 'lib/bisac/po_line_item.rb', line 9 def sequence_number @sequence_number end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/bisac/po_line_item.rb', line 11 def title @title end |
Class Method Details
.load_from_string(data) ⇒ Object
returns a new Bisac::POLineItem object using the data passed in as a string refer to the bisac spec for the expected format of the string
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bisac/po_line_item.rb', line 16 def self.load_from_string(data) raise ArgumentError, 'data must be a string' unless data.kind_of? String data.strip! item = self.new item.sequence_number = data[2,5].to_i item.po_number = data[7,13].strip item.line_item_number = data[21,10].strip # prefer the 13 digit ISBN if it exists (it's a non-standard, Pacstream extension) # fallback to the ISBN10 item.isbn = data[80,13] item.isbn ||= data[31,10] item.isbn.strip! item.qty = data[41,5].to_i item.catalogue_code = data[46,1].strip item.price = BigDecimal.new(data[47,6]) return item end |
Instance Method Details
#isbn10 ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/bisac/po_line_item.rb', line 53 def isbn10 if isbn? RBook::ISBN.convert_to_isbn10(@isbn) else @isbn end end |
#isbn? ⇒ Boolean
is the isbn for this product valid?
49 50 51 |
# File 'lib/bisac/po_line_item.rb', line 49 def isbn? RBook::ISBN.valid_isbn13?(@isbn || "") end |
#to_s ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bisac/po_line_item.rb', line 61 def to_s lines = ["","",""] lines[0] << "40" lines[0] << @sequence_number.to_s.rjust(5,"0") lines[0] << " " lines[0] << @po_number.to_s.ljust(11," ") lines[0] << " " # TODO lines[0] << "Y" # TODO lines[0] << @line_item_number.to_s.rjust(10,"0") lines[0] << pad_trunc(isbn10, 10) lines[0] << @qty.to_s.rjust(5, "0") lines[0] << "00000000000000000000000000000" # TODO lines[0] << " " # if we're ordering a valid ISBN, append a non-standard # ISBN13 to the line if isbn? lines[0] << @isbn end lines << "" lines[1] << "41" lines[1] << (@sequence_number + 1).to_s.rjust(5,"0") lines[1] << " " lines[1] << @po_number.to_s.ljust(11," ") lines[1] << " " lines[1] << pad_trunc(@title, 30) lines << "" lines[2] << "42" lines[2] << (@sequence_number + 2).to_s.rjust(5,"0") lines[2] << " " lines[2] << @po_number.to_s.ljust(11," ") lines[2] << " " # TODO lines[2] << pad_trunc(@author, 30) lines.join("\n") end |