Class: DataSrc
- Inherits:
-
Object
- Object
- DataSrc
- Defined in:
- lib/liquidoc.rb
Overview
class Build
Instance Method Summary collapse
- #ext ⇒ Object
- #file ⇒ Object
-
#initialize(sources) ⇒ DataSrc
constructor
Organizes metadata about an ingestible data source initialization means establishing a proper hash for the ‘data’ param.
- #name ⇒ Object
- #pattern ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(sources) ⇒ DataSrc
Organizes metadata about an ingestible data source initialization means establishing a proper hash for the ‘data’ param
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
# File 'lib/liquidoc.rb', line 597 def initialize sources @datasrc = {} @datasrc['file'] = sources @datasrc['ext'] = '' @datasrc['pattern'] = nil if sources.is_a? Hash # data var is a hash, so add 'ext' to it by extracting it from filename @datasrc['file'] = sources['file'] @datasrc['ext'] = File.extname(sources['file']) if (defined?(sources['pattern'])) @datasrc['pattern'] = sources['pattern'] end if (defined?(sources['type'])) @datasrc['type'] = sources['type'] end elsif sources.is_a? String @datasrc['ext'] = File.extname(sources) elsif sources.is_a? Array sources.each do |src| @datasrc['name'] = File.basename(@datasrc['file']) end else raise "InvalidDataSource" end end |
Instance Method Details
#ext ⇒ Object
626 627 628 |
# File 'lib/liquidoc.rb', line 626 def ext @datasrc['ext'] end |
#file ⇒ Object
622 623 624 |
# File 'lib/liquidoc.rb', line 622 def file @datasrc['file'] end |
#name ⇒ Object
630 631 632 |
# File 'lib/liquidoc.rb', line 630 def name File.basename(self.file,File.extname(self.file)) end |
#pattern ⇒ Object
655 656 657 |
# File 'lib/liquidoc.rb', line 655 def pattern @datasrc['pattern'] end |
#type ⇒ Object
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/liquidoc.rb', line 634 def type if @datasrc['type'] # if we're carrying a 'type' setting for data, pass it along datatype = @datasrc['type'] if datatype.downcase == "yaml" # This is an expected common error, so let's do the user a solid datatype = "yml" end else # If there's no 'type' defined, extract it from the filename and validate it unless @datasrc['ext'].downcase.match(/\.yml|\.json|\.xml|\.csv|\.adoc/) # @logger.error "Data file extension must be one of: .yml, .json, .xml, or .csv or else declared in config file." raise "FileExtensionUnknown" end datatype = self.ext datatype = datatype[1..-1] # removes leading dot char end unless datatype.downcase.match(/yml|json|xml|csv|regex|adoc/) # 'type' must be one of these permitted vals # @logger.error "Declared data type must be one of: yaml, json, xml, csv, or regex." raise "DataTypeUnrecognized" end datatype end |