Class: RBook::Bisac::Product
- Inherits:
-
Object
- Object
- RBook::Bisac::Product
- Defined in:
- lib/rbook/bisac/product.rb
Overview
Class to represent a single product line in a Bisac File. See RBook::Bisac for basic usage instructions.
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#edition ⇒ Object
Returns the value of attribute edition.
-
#imprint ⇒ Object
Returns the value of attribute imprint.
-
#isbn ⇒ Object
readonly
Returns the value of attribute isbn.
-
#price ⇒ Object
Returns the value of attribute price.
-
#pubdate ⇒ Object
Returns the value of attribute pubdate.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title ⇒ Object
Returns the value of attribute title.
-
#volume ⇒ Object
Returns the value of attribute volume.
-
#volumes ⇒ Object
Returns the value of attribute volumes.
Class Method Summary collapse
-
.from_string(s) ⇒ Object
takes a single line from a BISAC file and attempts to convert it to a Product object.
Instance Method Summary collapse
-
#initialize(isbn) ⇒ Product
constructor
Creates a new product object with the requested ISBN.
-
#to_s ⇒ Object
Returns the product as a single line ready for inserting into a BISAC file.
Constructor Details
#initialize(isbn) ⇒ Product
Creates a new product object with the requested ISBN. Must be a 10 digit ISBN.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbook/bisac/product.rb', line 12 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
#author ⇒ Object
Returns the value of attribute author.
8 9 10 |
# File 'lib/rbook/bisac/product.rb', line 8 def @author end |
#binding ⇒ Object
Returns the value of attribute binding.
9 10 11 |
# File 'lib/rbook/bisac/product.rb', line 9 def binding @binding end |
#edition ⇒ Object
Returns the value of attribute edition.
9 10 11 |
# File 'lib/rbook/bisac/product.rb', line 9 def edition @edition end |
#imprint ⇒ Object
Returns the value of attribute imprint.
9 10 11 |
# File 'lib/rbook/bisac/product.rb', line 9 def imprint @imprint end |
#isbn ⇒ Object (readonly)
Returns the value of attribute isbn.
8 9 10 |
# File 'lib/rbook/bisac/product.rb', line 8 def isbn @isbn end |
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/rbook/bisac/product.rb', line 8 def price @price end |
#pubdate ⇒ Object
Returns the value of attribute pubdate.
8 9 10 |
# File 'lib/rbook/bisac/product.rb', line 8 def pubdate @pubdate end |
#publisher ⇒ Object
Returns the value of attribute publisher.
8 9 10 |
# File 'lib/rbook/bisac/product.rb', line 8 def publisher @publisher end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/rbook/bisac/product.rb', line 9 def status @status end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/rbook/bisac/product.rb', line 8 def title @title end |
#volume ⇒ Object
Returns the value of attribute volume.
9 10 11 |
# File 'lib/rbook/bisac/product.rb', line 9 def volume @volume end |
#volumes ⇒ Object
Returns the value of attribute volumes.
9 10 11 |
# File 'lib/rbook/bisac/product.rb', line 9 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rbook/bisac/product.rb', line 46 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. = 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_s ⇒ Object
Returns the product as a single line ready for inserting into a BISAC file. Doesn’t have a n on the end
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 163 |
# File 'lib/rbook/bisac/product.rb', line 103 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 |