datafy 0.6.1 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09e762c66ae752ab2fb17cd1739408019164e135ed5e909826f1a538af2ae212'
4
- data.tar.gz: 198dbed672227d35b0180319a9ef9857b58dfdc77f52b86540bbec7a2e439ee3
3
+ metadata.gz: 320cc715a3d47996fe4bea5b4318e3e424044dd8871101c81359a0794597f614
4
+ data.tar.gz: 7abb830654ee3a45b8cb58b774f6c8518b3e6dc7d726261417c882a108502d51
5
5
  SHA512:
6
- metadata.gz: 04323d2e69ba66ce13412a7e28aa90db4c7c295070f9ff1f6f5c91303f8f59551476a1f33182c69824a1dc2980938afbc614b61db3fb5b733d4bfee1a433a578
7
- data.tar.gz: 85c4fd3567dd533e5994c364bd9cd8e7ce6e202ec72ae4a59d6e1103b7f782fb29e7595932bbb65a2ea7b1ec6feba54d124e14ecec96001bf3d1dcc09b8e0303
6
+ metadata.gz: 9bdd27e05d9085670fddf74c04e5dff800b1393cf33bcf1f4df44e0edecc1fe963c93ec4841c01273aeae26dc84a9fb5651a2aacf288aa8291faef16fdbbfe59
7
+ data.tar.gz: 556da67854784253598b1d49dcf236eb777a89bc84a1126695c98a24da85d45f43b14660ae81c22c0234f369a9f5a7a3cad5f0da670f19f9690746ad2410d2e4
@@ -4,15 +4,13 @@ require 'date'
4
4
  require 'logger'
5
5
  require_relative 'fileprovider'
6
6
 
7
- module BaseHarvester
7
+ module BaseDatafier
8
8
 
9
9
  include FileProvider
10
10
 
11
- # attr_accessor :errorMessage, :logFile, :logFileName, :showLog
12
-
13
11
  class HarvestError < StandardError
14
12
  attr_reader :message, :source
15
- def initialize(msg="default message", thing="BaseHarvester")
13
+ def initialize(msg="default message", thing="BaseDatafier")
16
14
  @message = msg
17
15
  @thing = thing
18
16
  super(msg)
@@ -22,6 +20,9 @@ module BaseHarvester
22
20
  # ================== Data Fields Section ==================
23
21
 
24
22
  v, $VERBOSE = $VERBOSE, nil
23
+ ##
24
+ # Metadata properties used to track the timing and success of the 'normal' properties.
25
+ # Optional for use in implementing classes, i.e. not required to be used, but will be present in the property sets
25
26
  BASE_HARVEST_DATA_FIELDS = {
26
27
  'Harvest When' => { property: :harvestWhen, comment: 'Date/Time of data harvesting' },
27
28
  'Harvest Successful?' => { property: :harvestSuccessful, comment: 'Boolean - was harvesting successful?' },
@@ -29,6 +30,10 @@ module BaseHarvester
29
30
  'Persist When' => { property: :persistWhen, comment: 'Date/Time of data persistence to CSV file' },
30
31
  }
31
32
  # --
33
+ ##
34
+ # Properties used to implement the key-value representation of the implementing classes' properties.
35
+ # Employed when the implementing class invokes the record method to, well, record an individual property and its value.
36
+ # Optional for use in implementing classes, i.e. not required to be used, but will be present in the Details record sets.
32
37
  DETAILS_PROPERTY_FIELDS = {
33
38
  'Class' => { property: :klass, comment: 'The class the details are being recorded for. (Base)' },
34
39
  'Detail' => { property: :detail, comment: 'The name of the field being recorded.' },
@@ -135,4 +140,4 @@ module BaseHarvester
135
140
  num_groups.map(&:join).join(',').reverse
136
141
  end
137
142
 
138
- end # module BaseHarvester
143
+ end # module BaseDatafier
@@ -1,19 +1,19 @@
1
1
  require 'set'
2
2
  require 'csv'
3
- require_relative 'baseharvester'
3
+ require_relative 'basedatafier'
4
4
 
5
- module CSVHarvester
5
+ module CSVifier
6
6
 
7
- include BaseHarvester
7
+ include BaseDatafier
8
8
  include FileProvider
9
9
 
10
10
  class << self
11
11
  def included(base)
12
- base.extend CSVHarvesterClassMethods
12
+ base.extend CSVifierClassMethods
13
13
  end
14
14
  end # class << self
15
15
 
16
- module CSVHarvesterClassMethods
16
+ module CSVifierClassMethods
17
17
 
18
18
  def logger
19
19
  @logger ||= Logger.new(logFileName,5,1024000)
@@ -24,7 +24,6 @@ module CSVHarvester
24
24
  end
25
25
 
26
26
  def data_fields
27
- # @data_fields ||= KEY_FIELDS.merge( PROPERTY_FIELDS, BaseHarvester::BASE_HARVEST_DATA_FIELDS )
28
27
  @data_fields ||= register_fields :data
29
28
  end
30
29
 
@@ -33,7 +32,6 @@ module CSVHarvester
33
32
  end
34
33
 
35
34
  def details_fields
36
- # @details_fields ||= KEY_FIELD.merge( BaseHarvester::DETAILS_PROPERTY_FIELDS, BaseHarvester::BASE_HARVEST_DATA_FIELDS )
37
35
  @details_fields ||= register_fields :details
38
36
  end
39
37
 
@@ -79,8 +77,8 @@ module CSVHarvester
79
77
  @details_fields = @data_fields.clone
80
78
  # --
81
79
  data_props = self.const_defined?(:PROPERTY_FIELDS) ? self::PROPERTY_FIELDS : {}
82
- @data_fields.merge!( data_props, BaseHarvester::BASE_HARVEST_DATA_FIELDS )
83
- @details_fields.merge!( BaseHarvester::DETAILS_PROPERTY_FIELDS, BaseHarvester::BASE_HARVEST_DATA_FIELDS )
80
+ @data_fields.merge!( data_props, BaseDatafier::BASE_HARVEST_DATA_FIELDS )
81
+ @details_fields.merge!( BaseDatafier::DETAILS_PROPERTY_FIELDS, BaseDatafier::BASE_HARVEST_DATA_FIELDS )
84
82
  attr_fields @data_fields
85
83
  attr_fields @details_fields
86
84
  return type.eql?(:data) ? @data_fields : @details_fields
@@ -146,7 +144,7 @@ module CSVHarvester
146
144
  fqname = FileProvider.getDataFileName("")
147
145
  logger.debug fqname
148
146
  puts fqname
149
- raise HarvestError.new "ERROR: method '#{self}::#{__method__}' not implemented source: CSVHarvester"
147
+ raise HarvestError.new "ERROR: method '#{self}::#{__method__}' not implemented source: CSVifier"
150
148
  end
151
149
  def prep_csv_file name, fields
152
150
  logger.debug "#{self.class}::#{__method__} name:'#{name}' fields:#{fields}"
@@ -245,7 +243,7 @@ module CSVHarvester
245
243
  @persistWhen = persist_when
246
244
  end
247
245
 
248
- end # module CSVHarvesterClassMethods
246
+ end # module CSVifierClassMethods
249
247
 
250
248
  def logger
251
249
  # puts "#{self.class}::#{__method__}"
@@ -346,7 +344,7 @@ module CSVHarvester
346
344
  logger.debug "#{self.class}::#{__method__}"
347
345
  record( property: :harvestSuccessful, value: false )
348
346
  record( property: :harvestMessage, value: error.message[0..150].gsub("\n", ' | ') )
349
- @errorMessage = error.full_message.to_s # @errorMessage declared in BaseHarvester, useful for debugging
347
+ @errorMessage = error.full_message.to_s # @errorMessage declared in BaseDatafier, useful for debugging
350
348
  end
351
349
 
352
350
  def csvRecord
@@ -525,4 +523,4 @@ module CSVHarvester
525
523
  return str
526
524
  end
527
525
 
528
- end # module CSVHarvester
526
+ end # module CSVifier
data/lib/datafy.rb CHANGED
@@ -1,9 +1,27 @@
1
- require_relative 'datafy/baseharvester'
1
+ require_relative 'datafy/basedatafier'
2
2
  require_relative 'datafy/fileprovider'
3
- require_relative 'datafy/csvharvester'
3
+ require_relative 'datafy/csvifier'
4
4
 
5
- class Datafy
6
- def self.hi
7
- puts "Hello world! Datafy here to help you persist Ruby attributes as data Fields."
5
+ module Datafy
6
+
7
+ def self.usage
8
+ puts "\nHello there.\nDatafy.usage here to help you persist Ruby attributes as data Fields; and store the data in CSV files.\n"
9
+ puts "The basic idea is simple: for each class whose instances you want to represent as data & save into a CSV file, you: "
10
+ puts "\t - establish class constants that identify the object attributes to dayafy, there are commonly two constants:"
11
+ puts "\t\t 1) KEY_FIELDS - establish the key fields for each object"
12
+ puts "\t\t 2) PROPERTY_FIELDS - establish the other )non-key) fields for each object"
13
+ puts "\t - register the property attributes with the class, via \"prop_accessor PROPERTY_FIELDS\""
14
+ my_loc = File.dirname(__FILE__)
15
+ # puts "I'm at #{my_loc}"
16
+ proto_src = File.join(my_loc, 'resources/Proto.rb')
17
+ proto_exists = File.exists? proto_src
18
+ # puts "Proto: #{proto_src} exists? #{proto_exists}"
19
+ if proto_exists
20
+ puts "\nHere's an example of a prototype class employing datafy:"
21
+ puts "--------------------------------------------------------"
22
+ contents = File.read(proto_src)
23
+ puts contents
24
+ puts "--------------------------------------------------------"
25
+ end
8
26
  end
9
27
  end
@@ -0,0 +1,35 @@
1
+ require 'datafy'
2
+
3
+ class Proto
4
+ include CSVifier
5
+ v, $VERBOSE = $VERBOSE, nil
6
+ KEY_FIELDS = {
7
+ 'Root' => { property: :root, comment: "Property providing information about the entity being datafied." },
8
+ 'ID' => { property: :id, comment: "Traditional ID property." },
9
+ }
10
+ PROPERTY_FIELDS = {
11
+ 'Introduction' => { property: :introduction, comment: "Informative material." },
12
+ 'Attribute' => { property: :attribute, comment: "Something of interest." }
13
+
14
+ }
15
+ $VERBOSE = v
16
+ prop_accessor PROPERTY_FIELDS # establish the class properties based upon the declared constants
17
+ # note: these property assignments will be included:
18
+ # KEY_FIELDS - declared above
19
+ # BaseDatafier::BASE_HARVEST_DATA_FIELDS - harvesting & persisting metadata
20
+ # BaseDatafier::DETAILS_PROPERTY_FIELDS - key-value details fields
21
+ end
22
+
23
+ proto = Proto.new
24
+ proto.harvest # assign values to properties, there are two main ways to accomplish this:
25
+
26
+ proto.id = 'XBCD' # standard assignment
27
+ proto.record( property: :attribute, value: "Hi there, I'm an attribute" ) # key-value 'details' assignment
28
+
29
+ proto.printCSVRecord # print the object's data as a CSV record
30
+ proto.printDetails # print the object's data as a set of key-valye (aka details) records
31
+
32
+ proto.persist # persist the object's attributes into CSV files,
33
+ # - one 'flat' file for normal records
34
+ # - one key-value file for the object's details
35
+ proto.printDataFiles # identify the CSV files
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datafy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Gerrard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Represent, record, and persist Ruby classes' attributes as CSV fields
14
14
  and persist them as data fields into CSV files. Each attribute has an internal class
@@ -21,9 +21,10 @@ extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
23
  - lib/datafy.rb
24
- - lib/datafy/BaseHarvester.rb
25
- - lib/datafy/CSVHarvester.rb
24
+ - lib/datafy/BaseDatafier.rb
25
+ - lib/datafy/CSVifier.rb
26
26
  - lib/datafy/FileProvider.rb
27
+ - lib/resources/Proto.rb
27
28
  homepage: ''
28
29
  licenses:
29
30
  - MIT