Class: Isbnify::IISBNA

Inherits:
Object
  • Object
show all
Defined in:
lib/isbnify/iisbna.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(isbn = "") ⇒ IISBNA

Returns a new instance of IISBNA.



9
10
11
12
# File 'lib/isbnify/iisbna.rb', line 9

def initialize(isbn = "")
  @isbn       = isbn.to_s
  @range_hash = xml_parse
end

Instance Attribute Details

#country_groupObject

Returns the value of attribute country_group.



7
8
9
# File 'lib/isbnify/iisbna.rb', line 7

def country_group
  @country_group
end

#group_hashObject

Returns the value of attribute group_hash.



7
8
9
# File 'lib/isbnify/iisbna.rb', line 7

def group_hash
  @group_hash
end

#isbnObject

Returns the value of attribute isbn.



7
8
9
# File 'lib/isbnify/iisbna.rb', line 7

def isbn
  @isbn
end

#prefixObject

Returns the value of attribute prefix.



7
8
9
# File 'lib/isbnify/iisbna.rb', line 7

def prefix
  @prefix
end

#publisherObject

Returns the value of attribute publisher.



7
8
9
# File 'lib/isbnify/iisbna.rb', line 7

def publisher
  @publisher
end

#range_hashObject

Returns the value of attribute range_hash.



7
8
9
# File 'lib/isbnify/iisbna.rb', line 7

def range_hash
  @range_hash
end

Instance Method Details

#create_valid_isbnObject



19
20
21
22
23
24
25
# File 'lib/isbnify/iisbna.rb', line 19

def create_valid_isbn
  random_group = range_hash[:"ISBNRangeMessage"][:"RegistrationGroups"][:"Group"].shuffle[0]
  group        = random_group[:Prefix]
  rule         = random_group[:Rules][:Rule].is_a?(Array) ? random_group[:Rules][:Rule].shuffle[0] : random_group[:Rules][:Rule]
  r_publisher  = random_publisher(rule)
  create_isbn(group, r_publisher)
end

#hyphinateObject



14
15
16
17
# File 'lib/isbnify/iisbna.rb', line 14

def hyphinate
  return "invalid international ISBN13 number" unless valid_prefix? && valid_group? && valid_publisher?
  hyphinate_with_values
end