Module: BaseDatafier

Includes:
FileProvider
Included in:
CSVifier
Defined in:
lib/datafy/BaseDatafier.rb

Defined Under Namespace

Modules: DataFieldsClassMethods Classes: HarvestError

Constant Summary collapse

BASE_HARVEST_DATA_FIELDS =

Metadata properties used to track the timing and success of the ‘normal’ properties. Optional for use in implementing classes, i.e. not required to be used, but will be present in the property sets

{
    'Harvest When'        => { property: :harvestWhen,       comment: 'Date/Time of data harvesting'              },
    'Harvest Successful?' => { property: :harvestSuccessful, comment: 'Boolean - was harvesting successful?'      },
    'Harvest Message'     => { property: :harvestMessage,    comment: 'Usually indicates harvesting problem'      },
    'Persist When'        => { property: :persistWhen,       comment: 'Date/Time of data persistence to CSV file' },
}
DETAILS_PROPERTY_FIELDS =

Properties used to implement the key-value representation of the implementing classes’ properties. Employed when the implementing class invokes the record method to, well, record an individual property and its value. Optional for use in implementing classes, i.e. not required to be used, but will be present in the Details record sets.

{
    'Class'   => { property: :klass,  comment: 'The class the details are being recorded for. (Base)'  },
    'Detail'  => { property: :detail, comment: 'The name of the field being recorded.'                 },
    'Index'   => { property: :index,  comment: 'Recording sequence, i.e. 1: first, 2: second, etc.'    },
    'Line'    => { property: :line,   comment: 'The specific detail.'   },
}

Instance Attribute Summary

Attributes included from FileProvider

#file_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileProvider

backupFile, #backupFile, dataDir, dataDir=, #dataTextFile, getBackupFileName, getDataDir, getDataFileName, getDir, getLogDir, localDir, localDir=, logDir, logDir=, #openLogFile, #removeFile

Class Method Details

.included(base) ⇒ Object


46
47
48
# File 'lib/datafy/BaseDatafier.rb', line 46

def included(base)
  base.extend DataFieldsClassMethods
end

Instance Method Details

#data_fieldsObject


120
121
122
# File 'lib/datafy/BaseDatafier.rb', line 120

def data_fields
    self.class.data_fields
end

#details_fieldsObject


124
125
126
# File 'lib/datafy/BaseDatafier.rb', line 124

def details_fields
    self.class.details_fields
end

#flattenTextLines(lines) ⇒ Object


132
133
134
# File 'lib/datafy/BaseDatafier.rb', line 132

def flattenTextLines lines
    lines.is_a?(Enumerable) ? lines.join(' ') : lines.to_s
end

#loggerObject

module DataFieldsClassMethods


116
117
118
# File 'lib/datafy/BaseDatafier.rb', line 116

def logger
    self.class.logger
end

#nowObject


128
129
130
# File 'lib/datafy/BaseDatafier.rb', line 128

def now
    DateTime.now.strftime('%l:%M:%S%P %b %-d, %Y ').strip
end

#numify(str) ⇒ Object


136
137
138
139
140
141
# File 'lib/datafy/BaseDatafier.rb', line 136

def numify str
    number = str.is_a?(String) ? str : str.to_s
    number.gsub!(/[^0-9]/,'')
    num_groups = number.to_s.chars.to_a.reverse.each_slice(3)
    num_groups.map(&:join).join(',').reverse
end