Class: ISBNdb::AccessKeySet
- Inherits:
-
Object
- Object
- ISBNdb::AccessKeySet
- Defined in:
- lib/isbndb/access_key_set.rb
Overview
The AccessKeySet is a simple class used to manage access keys. It is used primarily by the ruby_isbndb class to automatically advance access keys when necessary.
Instance Method Summary collapse
- #current_index ⇒ Object
-
#current_key ⇒ Object
Get the current key.
-
#initialize ⇒ AccessKeySet
constructor
Create the @access_keys array and then verify that the keys are valid keys.
-
#next_key ⇒ Object
Get the next key.
-
#next_key! ⇒ Object
Move the key pointer forward.
-
#prev_key ⇒ Object
Get the previous key.
-
#prev_key! ⇒ Object
Move the key pointer back.
-
#remove_key(key) ⇒ Object
Remove the given access key from the AccessKeySet.
-
#size ⇒ Object
Returns the total number of access keys in this set.
-
#to_s ⇒ Object
Pretty print the AccessKeySet.
-
#use_key(key) ⇒ Object
Tell Ruby ISBNdb to use a specified key.
Constructor Details
#initialize ⇒ AccessKeySet
Create the @access_keys array and then verify that the keys are valid keys.
7 8 9 |
# File 'lib/isbndb/access_key_set.rb', line 7 def initialize @access_keys ||= YAML::load(File.open('config/isbndb.yml'))['access_keys'] end |
Instance Method Details
#current_index ⇒ Object
16 17 18 |
# File 'lib/isbndb/access_key_set.rb', line 16 def current_index @current_index ||= 0 end |
#current_key ⇒ Object
Get the current key. It returns a string of the access key.
21 22 23 |
# File 'lib/isbndb/access_key_set.rb', line 21 def current_key @access_keys[current_index] end |
#next_key ⇒ Object
Get the next key.
32 33 34 |
# File 'lib/isbndb/access_key_set.rb', line 32 def next_key @access_keys[current_index+1] end |
#next_key! ⇒ Object
Move the key pointer forward.
26 27 28 29 |
# File 'lib/isbndb/access_key_set.rb', line 26 def next_key! @current_index = current_index + 1 current_key end |
#prev_key ⇒ Object
Get the previous key.
43 44 45 |
# File 'lib/isbndb/access_key_set.rb', line 43 def prev_key @access_keys[current_index-1] end |
#prev_key! ⇒ Object
Move the key pointer back.
37 38 39 40 |
# File 'lib/isbndb/access_key_set.rb', line 37 def prev_key! @current_index = current_index - 1 current_key end |
#remove_key(key) ⇒ Object
Remove the given access key from the AccessKeySet.
55 56 57 |
# File 'lib/isbndb/access_key_set.rb', line 55 def remove_key(key) @access_keys.delete(key) end |
#size ⇒ Object
Returns the total number of access keys in this set.
12 13 14 |
# File 'lib/isbndb/access_key_set.rb', line 12 def size @access_keys.size end |
#to_s ⇒ Object
Pretty print the AccessKeySet
60 61 62 |
# File 'lib/isbndb/access_key_set.rb', line 60 def to_s "#<AccessKeySet @keys=#{@access_keys.inspect}>" end |
#use_key(key) ⇒ Object
Tell Ruby ISBNdb to use a specified key. If the key does not exist, it is added to the set and set as the current key.
49 50 51 52 |
# File 'lib/isbndb/access_key_set.rb', line 49 def use_key(key) @current_index = @access_keys.index(key) || @access_keys.push(key).index(key) current_key end |