datafy 0.7.4 → 1.1

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: 145a7af1e48a72862b262510783ddadbecc36bb5736000cb8f0620ac18e7712a
4
- data.tar.gz: c6f91d1eb32c3fd05181f40288e3a0c26c91e50ce3e06f7561f5acd768bb16b0
3
+ metadata.gz: f7db53eae7e64ecd16eaa09db8451804d45221a80aa561f4fad07f751f16dffc
4
+ data.tar.gz: 371ec865101714566cd6bb56b701c4bb9ae17318c3ae0e964caecf6d6bef08a1
5
5
  SHA512:
6
- metadata.gz: e91fae53634bc296615aa7258ec0f9a4a84831081e053b4b5cc7d789d35b9546a256a143d4e6ebb75fe4508f8aa05d159600e69493e2984b050259e421270c1a
7
- data.tar.gz: 9bd5e18eb4cf6038b33c978eb99c2e883ccdb1a130b32bbd7450d88699930547bd69bf9ee51e96f3ba5ae48dd43b284a78a4ab9d2791afdf1d3e8155913353d4
6
+ metadata.gz: 0cb7cf2bb2e101369f91d425d2b6c0fdc8f8796e5a77547c74a3c862579e195d47f107603572beaf3fc524bec4b9234f28b452b775bf47711707fa4c709432f2
7
+ data.tar.gz: 265a8feeb867f8d01be900049f9ce85939ce30ed986fbfb70bbea3b8624c21bc36b16bdffb98dc9c26f8fb628cc6172877cb8f8c8b3e0a2a2d66679a8e87a4de
@@ -1,4 +1,4 @@
1
- # print "Executing: #{__FILE__}"
1
+ # print "Loading: #{__FILE__}"
2
2
 
3
3
  require 'date'
4
4
  require 'logger'
@@ -8,8 +8,6 @@ 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
13
  def initialize(msg="default message", thing="BaseDatafier")
@@ -22,6 +20,9 @@ module BaseDatafier
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 BaseDatafier
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.' },
@@ -50,7 +55,7 @@ module BaseDatafier
50
55
  end
51
56
 
52
57
  def logFileName
53
- @logFileName ||= FileProvider.getDataFileName("#{self.class}.log")
58
+ @logFileName ||= FileProvider.getDataFileName("#{self}.log")
54
59
  end
55
60
 
56
61
  def attr_fields fields
@@ -90,14 +95,6 @@ module BaseDatafier
90
95
  attr_fields fields
91
96
  end
92
97
 
93
- # def register_details_fields fields
94
- # return if fields.nil?
95
- # @details_fields = {} if @details_fields.nil?
96
- # @details_fields.merge!(fields)
97
- # @details_fields.merge!(BASE_HARVEST_DATA_FIELDS)
98
- # attr_fields @details_fields
99
- # end
100
-
101
98
  def details_fields
102
99
  # puts "#{self.class}::#{__method__}"
103
100
  if @details_fields.nil?
@@ -323,6 +323,11 @@ module CSVifier
323
323
  end
324
324
  end
325
325
 
326
+ def resetData
327
+ resetDataFields
328
+ resetDetails
329
+ end
330
+
326
331
  def resetDataFields
327
332
  data_fields.each do |fieldName,parts|
328
333
  methodName = "#{parts[:property].to_s}="
@@ -1,4 +1,4 @@
1
- # puts "Executing: #{__FILE__}"
1
+ # puts "Loading: #{__FILE__}"
2
2
 
3
3
  require 'fileutils'
4
4
 
@@ -30,7 +30,7 @@ module FileProvider
30
30
 
31
31
  def self.getDir dir='data'
32
32
  dir_name = "#{localDir}/#{dir}".gsub(/[\/]+/,'/')
33
- unless Dir.exists?(dir_name)
33
+ unless Dir.exist?(dir_name)
34
34
  Dir.mkdir(dir_name)
35
35
  end
36
36
  return dir_name
data/lib/datafy.rb CHANGED
@@ -5,11 +5,11 @@ require_relative 'datafy/csvifier'
5
5
  module Datafy
6
6
 
7
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"
8
+ puts "\nHi there. Datafy.usage here to help you persist Ruby attributes as data fields in CSV files.\n"
9
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:"
10
+ puts "\t - establish class constants that identify the object attributes to datafy; there are commonly two constants:"
11
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"
12
+ puts "\t\t 2) PROPERTY_FIELDS - establish the other, non-key, fields for each object"
13
13
  puts "\t - register the property attributes with the class, via \"prop_accessor PROPERTY_FIELDS\""
14
14
  my_loc = File.dirname(__FILE__)
15
15
  # puts "I'm at #{my_loc}"
@@ -0,0 +1,82 @@
1
+ require 'datafy'
2
+ class DatafyDemo
3
+ include CSVifier
4
+ v, $VERBOSE = $VERBOSE, nil
5
+ KEY_FIELDS = {
6
+ 'Root' => { property: :root, comment: "Property providing information about the entity being datafied." },
7
+ 'ID' => { property: :id, comment: "Traditional ID property." },
8
+ }
9
+ PROPERTY_FIELDS = {
10
+ 'Introduction' => { property: :introduction, comment: "Informative material." },
11
+ 'Attribute' => { property: :attribute, comment: "Something of interest." }
12
+
13
+ }
14
+ $VERBOSE = v
15
+ prop_accessor PROPERTY_FIELDS # establish the class properties based upon the declared constants
16
+ # note: these property assignments will be included:
17
+ # KEY_FIELDS - declared above
18
+ # BaseDatafier::BASE_HARVEST_DATA_FIELDS - harvesting & persisting metadata
19
+ # BaseDatafier::DETAILS_PROPERTY_FIELDS - key-value details fields
20
+ end
21
+
22
+
23
+ puts " "
24
+ puts "====================================="
25
+ puts "Creating new DatafyDemo object 'demo'"
26
+ puts "-------------------------------------"
27
+ puts "> demo = DatafyDemo.new"
28
+ demo = DatafyDemo.new
29
+
30
+ puts ""
31
+ puts "===================================="
32
+ puts "Assigning values to demo, two forms:"
33
+ puts "------------------------------------"
34
+ # --
35
+ puts "> demo.id = 'XBCD'"
36
+ puts " # standard assignment, assigns value to object property 'id', does NOT establish a details key-value record"
37
+ demo.id = 'XBCD' # standard assignment, i.e. typical 'wide' form
38
+ # --
39
+ puts "> demo.record( property: :attribute, value: 'Hi there, I'm an DataDemo attribute ' )"
40
+ puts " # key-value 'details' record created for 'attribute' property AND a details key-value record is established"
41
+ demo.record( property: :attribute, value: "Hi there, I'm an attribute" ) # key-value 'details' assignment, i.e. 'tall' form
42
+
43
+ puts ""
44
+ puts "==============="
45
+ puts "Harvesting demo"
46
+ puts "establish the time & other data about when harvesting occurred and its success or failure"
47
+ puts "---------------"
48
+ puts "> demo.harvest"
49
+ demo.harvest
50
+
51
+ puts ""
52
+ puts "================================"
53
+ puts "Printing demo's data, two forms:"
54
+ puts "--------------------------------"
55
+ puts ""
56
+ puts "> demo.printCSVRecord"
57
+ puts " # print the object's data as a CSV record"
58
+ demo.printCSVRecord
59
+ puts " "
60
+ puts "> demo.printDetails"
61
+ puts " # print the object's data as a set of key-value (aka details) records"
62
+ puts " # note: ONLY those properties instantiated with 'demo.record(...)' exist as details"
63
+ demo.printDetails
64
+
65
+ puts ""
66
+ puts "=============================================="
67
+ puts "Persist the object's attributes into CSV files"
68
+ puts " creates 2 CSV files:"
69
+ puts " - one 'flat' file for normal CSV records"
70
+ puts " - one key-value file for the object's details"
71
+ puts "-----------------------------------------------"
72
+ puts "> demo.persist"
73
+ demo.persist
74
+
75
+ puts ""
76
+ puts "================================"
77
+ puts "Identify the persisted CSV files"
78
+ puts "--------------------------------"
79
+ puts "> demo.printDataFiles"
80
+ demo.printDataFiles
81
+
82
+ puts "\n\t\t That's all, Folks."
@@ -1,6 +1,7 @@
1
1
  require 'datafy'
2
+
2
3
  class Proto
3
- include CSVifier
4
+ include CSVifier # core implementation mudule
4
5
  v, $VERBOSE = $VERBOSE, nil
5
6
  KEY_FIELDS = {
6
7
  'Root' => { property: :root, comment: "Property providing information about the entity being datafied." },
@@ -14,7 +15,7 @@ class Proto
14
15
  $VERBOSE = v
15
16
  prop_accessor PROPERTY_FIELDS # establish the class properties based upon the declared constants
16
17
  # note: these property assignments will be included:
17
- # KEY_FIELDS - declared above
18
+ # KEY_FIELDS - declared above
18
19
  # BaseDatafier::BASE_HARVEST_DATA_FIELDS - harvesting & persisting metadata
19
20
  # BaseDatafier::DETAILS_PROPERTY_FIELDS - key-value details fields
20
21
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datafy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Gerrard
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-03-31 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Represent, record, and persist Ruby classes' attributes as CSV fields
14
13
  and persist them as data fields into CSV files. Each attribute has an internal class
@@ -24,12 +23,12 @@ files:
24
23
  - lib/datafy/BaseDatafier.rb
25
24
  - lib/datafy/CSVifier.rb
26
25
  - lib/datafy/FileProvider.rb
26
+ - lib/resources/DatafyDemo.rb
27
27
  - lib/resources/Proto.rb
28
28
  homepage: ''
29
29
  licenses:
30
30
  - MIT
31
31
  metadata: {}
32
- post_install_message:
33
32
  rdoc_options: []
34
33
  require_paths:
35
34
  - lib
@@ -44,8 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
43
  - !ruby/object:Gem::Version
45
44
  version: '0'
46
45
  requirements: []
47
- rubygems_version: 3.3.11
48
- signing_key:
46
+ rubygems_version: 4.0.9
49
47
  specification_version: 4
50
48
  summary: Record class attributes as data fields, with simple property names and human-oriented
51
49
  names, and persist into CSV files.