Class: Zold::TreeWallets
- Inherits:
-
Object
- Object
- Zold::TreeWallets
- Defined in:
- lib/zold/tree_wallets.rb
Overview
Collection of local wallets, in a tree of directories
Instance Method Summary collapse
-
#all ⇒ Object
Returns the list of their IDs (as plain text).
- #find(id) {|Wallet.new( File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/') + Wallet::EXT) )| ... } ⇒ Object
-
#initialize(dir) ⇒ TreeWallets
constructor
A new instance of TreeWallets.
- #path ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dir) ⇒ TreeWallets
Returns a new instance of TreeWallets.
34 35 36 |
# File 'lib/zold/tree_wallets.rb', line 34 def initialize(dir) @dir = dir end |
Instance Method Details
#all ⇒ Object
Returns the list of their IDs (as plain text)
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/zold/tree_wallets.rb', line 48 def all DirItems.new(path).fetch.select do |f| next unless f.end_with?(Wallet::EXT) basename = File.basename(f, Wallet::EXT) file = File.join(path, f) File.file?(file) && !File.directory?(file) && basename =~ /^[0-9a-fA-F]{16}$/ && Id.new(basename).to_s == basename end.map { |w| Id.new(File.basename(w, Wallet::EXT)) } end |
#find(id) {|Wallet.new( File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/') + Wallet::EXT) )| ... } ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/zold/tree_wallets.rb', line 60 def find(id) raise 'Id can\'t be nil' if id.nil? raise 'Id must be of type Id' unless id.is_a?(Id) yield Wallet.new( File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/') + Wallet::EXT) ) end |
#path ⇒ Object
42 43 44 45 |
# File 'lib/zold/tree_wallets.rb', line 42 def path FileUtils.mkdir_p(@dir) File.(@dir) end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/zold/tree_wallets.rb', line 38 def to_s path end |