Class: Bisac::Product

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

Overview

Class to represent a single product line in a Bisac File. See Bisac::Message for basic usage instructions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(isbn) ⇒ Product

Creates a new product object with the requested ISBN. Must be a 10 digit ISBN.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bisac/product.rb', line 11

def initialize(isbn)
  raise ArgumentError, 'isbn must 10 chars or less' if isbn.to_s.length > 10

  @isbn = isbn.to_s
  @title = ""
  @author = ""
  @price = ""
  @pubdate = ""
  @publisher = ""
  @imprint = ""
  @volumes = ""
  @edition = ""
  @binding = ""
  @volume = ""
  @status = ""
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



7
8
9
# File 'lib/bisac/product.rb', line 7

def author
  @author
end

#bindingObject

Returns the value of attribute binding.



8
9
10
# File 'lib/bisac/product.rb', line 8

def binding
  @binding
end

#editionObject

Returns the value of attribute edition.



8
9
10
# File 'lib/bisac/product.rb', line 8

def edition
  @edition
end

#imprintObject

Returns the value of attribute imprint.



8
9
10
# File 'lib/bisac/product.rb', line 8

def imprint
  @imprint
end

#isbnObject (readonly)

Returns the value of attribute isbn.



7
8
9
# File 'lib/bisac/product.rb', line 7

def isbn
  @isbn
end

#priceObject

Returns the value of attribute price.



7
8
9
# File 'lib/bisac/product.rb', line 7

def price
  @price
end

#pubdateObject

Returns the value of attribute pubdate.



7
8
9
# File 'lib/bisac/product.rb', line 7

def pubdate
  @pubdate
end

#publisherObject

Returns the value of attribute publisher.



7
8
9
# File 'lib/bisac/product.rb', line 7

def publisher
  @publisher
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/bisac/product.rb', line 8

def status
  @status
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/bisac/product.rb', line 7

def title
  @title
end

#volumeObject

Returns the value of attribute volume.



8
9
10
# File 'lib/bisac/product.rb', line 8

def volume
  @volume
end

#volumesObject

Returns the value of attribute volumes.



8
9
10
# File 'lib/bisac/product.rb', line 8

def volumes
  @volumes
end

Class Method Details

.from_string(s) ⇒ Object

takes a single line from a BISAC file and attempts to convert it to a Product object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bisac/product.rb', line 45

def self.from_string(s)
  s = s.to_s
  return nil if s.length < 259
  product = self.new(s[0,10])
  product.title = s[15,30].strip
  product.author = s[46,30].strip
  product.price = s[79,7].strip if s[79,7].strip.match(/\A\d{0,7}\Z/)
  product.pubdate = s[87,6].strip if s[87,6].strip.match(/\A\d{6}\Z/)
  product.publisher = s[94,10].strip
  product.imprint = s[105,14].strip
  product.volumes = s[120,3].strip
  product.edition = s[124,2].strip
  product.binding = s[127,2].strip
  product.volume = s[130,3].strip
  product.status = s[153,3].strip
  return product
end

Instance Method Details

#to_sObject

Returns the product as a single line ready for inserting into a BISAC file. Doesn’t have a n on the end



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/bisac/product.rb', line 102

def to_s
  content = ""
  content << @isbn[0,10].ljust(10) # 10 digit isbn
  content << "1"
  content << "N"
  content << "N"
  content << "B"
  content << "N"
  content << @title[0,30].ljust(30)
  content << "N"
  content << @author[0,30].ljust(30)
  content << "N"
  content << "A" # author role
  content << "N"
  content << @price[0,7].rjust(7,"0") # current price
  content << "N"
  content << @pubdate[0,6].ljust(6) # published date
  content << "N"
  content << @publisher[0,10].ljust(10) # publisher
  content << "N"
  content << @imprint[0,14].ljust(14) #imprint
  content << "N"
  content << @volumes[0,3].rjust(3,"0") # volumes included in this isbn
  content << "N"
  content << @edition[0,2].rjust(2,"0") # edition
  content << "N"
  content << @binding[0,2].rjust(2,"0") # binding
  content << "N"
  content << @volume[0,3].rjust(3,"0") # volume number
  content << "N"
  content << "0000000" # new price
  content << "N"
  content << "000000" # new price effective date
  content << "N"
  content << "   " # audience type
  content << "N"
  content << @status[0,3].rjust(3) # status
  content << "N"
  content << "      " # available date. only use for status' like NYP
  content << "N"
  content << "          " # alternate isbn
  content << "N"
  content << "999999" # out of print date. only use for status == OP
  content << "N"
  content << "   " # geographic restrictions
  content << "N"
  content << "        " # library of congress catalogue number
  content << "N"
  content << "".ljust(40) # series title
  content << "N"
  content << "0" # price code for current price
  content << "N"
  content << "0" # price code for new price
  content << "N"
  content << "0000000" # freight pass through price
  content << "N"
  content << "000000" # new freight pass through price
  content << "00000" # last changed date

  return content
end