Class: RBook::Bisac::PO

Inherits:
Object
  • Object
show all
Defined in:
lib/rbook/bisac/po.rb

Overview

Represents a single BISAC purchase order

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePO

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

#backorderObject

Returns the value of attribute backorder.



12
13
14
# File 'lib/rbook/bisac/po.rb', line 12

def backorder
  @backorder
end

#cancellation_dateObject

Returns the value of attribute cancellation_date.



12
13
14
# File 'lib/rbook/bisac/po.rb', line 12

def cancellation_date
  @cancellation_date
end

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/rbook/bisac/po.rb', line 10

def date
  @date
end

#destination_sanObject

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_suffixObject

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_actionObject

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_amountObject

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_beforeObject

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

#filenameObject

Returns the value of attribute filename.



10
11
12
# File 'lib/rbook/bisac/po.rb', line 10

def filename
  @filename
end

#format_versionObject

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_copiesObject

Returns the value of attribute invoice_copies.



14
15
16
# File 'lib/rbook/bisac/po.rb', line 14

def invoice_copies
  @invoice_copies
end

#itemsObject

Returns the value of attribute items.



16
17
18
# File 'lib/rbook/bisac/po.rb', line 16

def items
  @items
end

#po_numberObject

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_nameObject

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_sanObject

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_suffixObject

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_instructionsObject

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.build_message(data)
end

.parse_file(input) {|self.build_message(data)| ... } ⇒ Object

return all POs from a BISAC file

Yields:

  • (self.build_message(data))

Raises:

  • (ArgumentError)


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.build_message(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.build_message(data) if data.size > 0
end