Class: RBook::Bisac::PO
- Inherits:
-
Object
- Object
- RBook::Bisac::PO
- Defined in:
- lib/rbook/bisac/po.rb
Overview
Represents a single BISAC purchase order
Instance Attribute Summary collapse
-
#backorder ⇒ Object
Returns the value of attribute backorder.
-
#cancellation_date ⇒ Object
Returns the value of attribute cancellation_date.
-
#date ⇒ Object
Returns the value of attribute date.
-
#destination_san ⇒ Object
Returns the value of attribute destination_san.
-
#destination_suffix ⇒ Object
Returns the value of attribute destination_suffix.
-
#do_not_exceed_action ⇒ Object
Returns the value of attribute do_not_exceed_action.
-
#do_not_exceed_amount ⇒ Object
Returns the value of attribute do_not_exceed_amount.
-
#do_not_ship_before ⇒ Object
Returns the value of attribute do_not_ship_before.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format_version ⇒ Object
Returns the value of attribute format_version.
-
#invoice_copies ⇒ Object
Returns the value of attribute invoice_copies.
-
#items ⇒ Object
Returns the value of attribute items.
-
#po_number ⇒ Object
Returns the value of attribute po_number.
-
#source_name ⇒ Object
Returns the value of attribute source_name.
-
#source_san ⇒ Object
Returns the value of attribute source_san.
-
#source_suffix ⇒ Object
Returns the value of attribute source_suffix.
-
#special_instructions ⇒ Object
Returns the value of attribute special_instructions.
Class Method Summary collapse
-
.load_from_file(input) ⇒ Object
reads a bisac text file into memory.
-
.load_from_string(input) ⇒ Object
creates a RBook::Bisac::PO object from a string.
-
.parse_file(input) {|self.build_message(data)| ... } ⇒ Object
return all POs from a BISAC file.
Instance Method Summary collapse
-
#initialize ⇒ PO
constructor
creates a new RBook::Bisac::PO object.
Constructor Details
#initialize ⇒ PO
creates a new RBook::Bisac::PO object
19 20 21 |
# File 'lib/rbook/bisac/po.rb', line 19 def initialize @items = [] end |
Instance Attribute Details
#backorder ⇒ Object
Returns the value of attribute backorder.
12 13 14 |
# File 'lib/rbook/bisac/po.rb', line 12 def backorder @backorder end |
#cancellation_date ⇒ Object
Returns the value of attribute cancellation_date.
12 13 14 |
# File 'lib/rbook/bisac/po.rb', line 12 def cancellation_date @cancellation_date end |
#date ⇒ Object
Returns the value of attribute date.
10 11 12 |
# File 'lib/rbook/bisac/po.rb', line 10 def date @date end |
#destination_san ⇒ Object
Returns the value of attribute destination_san.
11 12 13 |
# File 'lib/rbook/bisac/po.rb', line 11 def destination_san @destination_san end |
#destination_suffix ⇒ Object
Returns the value of attribute destination_suffix.
11 12 13 |
# File 'lib/rbook/bisac/po.rb', line 11 def destination_suffix @destination_suffix end |
#do_not_exceed_action ⇒ Object
Returns the value of attribute do_not_exceed_action.
13 14 15 |
# File 'lib/rbook/bisac/po.rb', line 13 def do_not_exceed_action @do_not_exceed_action end |
#do_not_exceed_amount ⇒ Object
Returns the value of attribute do_not_exceed_amount.
13 14 15 |
# File 'lib/rbook/bisac/po.rb', line 13 def do_not_exceed_amount @do_not_exceed_amount end |
#do_not_ship_before ⇒ Object
Returns the value of attribute do_not_ship_before.
15 16 17 |
# File 'lib/rbook/bisac/po.rb', line 15 def do_not_ship_before @do_not_ship_before end |
#filename ⇒ Object
Returns the value of attribute filename.
10 11 12 |
# File 'lib/rbook/bisac/po.rb', line 10 def filename @filename end |
#format_version ⇒ Object
Returns the value of attribute format_version.
10 11 12 |
# File 'lib/rbook/bisac/po.rb', line 10 def format_version @format_version end |
#invoice_copies ⇒ Object
Returns the value of attribute invoice_copies.
14 15 16 |
# File 'lib/rbook/bisac/po.rb', line 14 def invoice_copies @invoice_copies end |
#items ⇒ Object
Returns the value of attribute items.
16 17 18 |
# File 'lib/rbook/bisac/po.rb', line 16 def items @items end |
#po_number ⇒ Object
Returns the value of attribute po_number.
12 13 14 |
# File 'lib/rbook/bisac/po.rb', line 12 def po_number @po_number end |
#source_name ⇒ Object
Returns the value of attribute source_name.
9 10 11 |
# File 'lib/rbook/bisac/po.rb', line 9 def source_name @source_name end |
#source_san ⇒ Object
Returns the value of attribute source_san.
9 10 11 |
# File 'lib/rbook/bisac/po.rb', line 9 def source_san @source_san end |
#source_suffix ⇒ Object
Returns the value of attribute source_suffix.
9 10 11 |
# File 'lib/rbook/bisac/po.rb', line 9 def source_suffix @source_suffix end |
#special_instructions ⇒ Object
Returns the value of attribute special_instructions.
14 15 16 |
# File 'lib/rbook/bisac/po.rb', line 14 def special_instructions @special_instructions end |
Class Method Details
.load_from_file(input) ⇒ Object
reads a bisac text file into memory. input should be a string that specifies the file path
25 26 27 28 29 |
# File 'lib/rbook/bisac/po.rb', line 25 def self.load_from_file(input) $stderr.puts "WARNING: RBook::Bisac::PO.load_from_file is deprecated. It only returns the first PO in the file. use parse_file instead." self.parse_file(input) { |msg| return msg } return nil end |
.load_from_string(input) ⇒ Object
creates a RBook::Bisac::PO object from a string. Input should be a complete bisac file as a string
56 57 58 59 |
# File 'lib/rbook/bisac/po.rb', line 56 def self.load_from_string(input) data = input.split("\n") return self.(data) end |
.parse_file(input) {|self.build_message(data)| ... } ⇒ Object
return all POs from a BISAC file
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rbook/bisac/po.rb', line 32 def self.parse_file(input, &block) raise ArgumentError, 'no file provided' if input.nil? raise RBook::InvalidFileError, 'Invalid file' unless File.exist?(input) data = [] File.open(input, "r") do |f| f.each_line do |l| data << l # yield each message found in the file. A line starting with # 90 is the footer to a PO if data.last[0,2] == "90" yield self.(data) data = [] end end end # if we've got to the end of the file, and haven't hit a footer line yet, the file # is probably malformed. Call build_message anyway, and let it detect any errors yield self.(data) if data.size > 0 end |