class Getapp::Import::Capterra
Getapp::Import::Capterra
Class¶ ↑
Main entry point for Capterra
Products
Import
. Parse load Yaml supplied file and convert Capterra
Products
into Getapp
Products
format.
Constants
- SUPPORTED_FILE_FORMATS
Attributes
path[R]
products[R]
verbose[R]
Public Class Methods
new(path, verbose = false)
click to toggle source
Getapp::Import::Capterra
initialize Method¶ ↑
@params, Boolean
path is a valid file path with format YAML
@return Getapp::Import::Capterra
instance
# File lib/getapp/import/capterra.rb, line 26 def initialize(path, verbose = false) @path = path @verbose = verbose end
Public Instance Methods
import()
click to toggle source
Getapp::Import::Capterra
import Public Method¶ ↑
Call all the privates method
@return Boolean
# File lib/getapp/import/capterra.rb, line 37 def import check_file_exist? validate_file_formats parse_products import_products true end
Private Instance Methods
check_file_exist?()
click to toggle source
Getapp::Import::Capterra
check_file_exist? Private Method¶ ↑
Check that file exist on the give path. Raise an Getapp::Capterra::FileNotFound
exception if file is missing.
# File lib/getapp/import/capterra.rb, line 53 def check_file_exist? puts "Capterra: Checking file exist" if verbose puts "Capterra: File does not exist." if verbose raise Getapp::Capterra::FileNotFound, "Capterra: File does not exist." unless File.exist?(path) end
format_products()
click to toggle source
Getapp::Import::Capterra
format_products
Private Method¶ ↑
Transform Capterra
Product format into Getapp
Product format
import_products()
click to toggle source
Getapp::Import::Capterra
import_products
Private Method¶ ↑
Import
formatted products into persistent storage.
@return NilClass
# File lib/getapp/import/capterra.rb, line 97 def import_products Getapp::Import::Products.new(format_products, verbose).import end
parse_products()
click to toggle source
Getapp::Import::Capterra
parse_products
Private Method¶ ↑
Load yaml file into JSON format.
# File lib/getapp/import/capterra.rb, line 75 def parse_products puts "Capterra: Parsing products" if verbose @products = YAML.load_file(path) end
validate_file_formats()
click to toggle source
Getapp::Import::Capterra
validate_file_formats
Private Method¶ ↑
Check that file have valid format. Raise an Getapp::Capterra::FileFormatNotSupported
exception if file format is not included in list.
# File lib/getapp/import/capterra.rb, line 65 def validate_file_formats file_format = File.extname(path) message = "File format (#{file_format}) not supported yet." raise Getapp::Capterra::FileFormatNotSupported, message unless SUPPORTED_FILE_FORMATS.include?(file_format) end