Class: Graybook
Defined Under Namespace
Modules: Exporter, Importer Classes: Problem
Constant Summary collapse
- VERSION =
'1.1.1'
Instance Attribute Summary collapse
-
#exporters ⇒ Object
Returns the value of attribute exporters.
-
#importers ⇒ Object
Returns the value of attribute importers.
Class Method Summary collapse
Instance Method Summary collapse
- #export(importer, exporter, options) ⇒ Object
-
#find_importer(options) ⇒ Object
Searches registered importers for one that will handle the given options.
-
#get(*args) ⇒ Object
Fetches contacts from various services or filetypes.
-
#initialize ⇒ Graybook
constructor
A new instance of Graybook.
Constructor Details
#initialize ⇒ Graybook
Returns a new instance of Graybook.
59 60 61 62 |
# File 'lib/graybook.rb', line 59 def initialize self.importers = {} self.exporters = {} end |
Instance Attribute Details
#exporters ⇒ Object
Returns the value of attribute exporters.
16 17 18 |
# File 'lib/graybook.rb', line 16 def exporters @exporters end |
#importers ⇒ Object
Returns the value of attribute importers.
15 16 17 |
# File 'lib/graybook.rb', line 15 def importers @importers end |
Class Method Details
.get(*args) ⇒ Object
18 19 20 |
# File 'lib/graybook.rb', line 18 def self.get( *args ) instance.get( *args ) end |
.register(name, adapter_class) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graybook.rb', line 22 def self.register(name, adapter_class) case adapter = adapter_class.new when Importer::Base instance.importers[name.to_sym] = adapter when Exporter::Base instance.exporters[name.to_sym] = adapter else return nil end end |
Instance Method Details
#export(importer, exporter, options) ⇒ Object
33 34 35 |
# File 'lib/graybook.rb', line 33 def export( importer, exporter, ) exporter.export importer.import( ) end |
#find_importer(options) ⇒ Object
Searches registered importers for one that will handle the given options
38 39 40 41 |
# File 'lib/graybook.rb', line 38 def find_importer( ) importers.each{ |key, importer| return importer if importer =~ } nil end |
#get(*args) ⇒ Object
Fetches contacts from various services or filetypes. The default is to return an array of hashes - Graybookâs internal format
Handles several different calls:
get( :username => '[email protected]', :password => 'whatever' )
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/graybook.rb', line 48 def get( *args ) = args.last.is_a?(Hash) ? args.pop : {} to_format = exporters[:basic] source = (importers[args.first.to_sym] rescue nil) || find_importer() return nil unless to_format return nil unless source export source, to_format, end |