datafy 0.6.1 → 0.7.4
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 +4 -4
- data/lib/datafy/{BaseHarvester.rb → BaseDatafier.rb} +3 -3
- data/lib/datafy/{CSVHarvester.rb → CSVifier.rb} +11 -13
- data/lib/datafy.rb +23 -5
- data/lib/resources/Proto.rb +34 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 145a7af1e48a72862b262510783ddadbecc36bb5736000cb8f0620ac18e7712a
|
4
|
+
data.tar.gz: c6f91d1eb32c3fd05181f40288e3a0c26c91e50ce3e06f7561f5acd768bb16b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e91fae53634bc296615aa7258ec0f9a4a84831081e053b4b5cc7d789d35b9546a256a143d4e6ebb75fe4508f8aa05d159600e69493e2984b050259e421270c1a
|
7
|
+
data.tar.gz: 9bd5e18eb4cf6038b33c978eb99c2e883ccdb1a130b32bbd7450d88699930547bd69bf9ee51e96f3ba5ae48dd43b284a78a4ab9d2791afdf1d3e8155913353d4
|
@@ -4,7 +4,7 @@ require 'date'
|
|
4
4
|
require 'logger'
|
5
5
|
require_relative 'fileprovider'
|
6
6
|
|
7
|
-
module
|
7
|
+
module BaseDatafier
|
8
8
|
|
9
9
|
include FileProvider
|
10
10
|
|
@@ -12,7 +12,7 @@ module BaseHarvester
|
|
12
12
|
|
13
13
|
class HarvestError < StandardError
|
14
14
|
attr_reader :message, :source
|
15
|
-
def initialize(msg="default message", thing="
|
15
|
+
def initialize(msg="default message", thing="BaseDatafier")
|
16
16
|
@message = msg
|
17
17
|
@thing = thing
|
18
18
|
super(msg)
|
@@ -135,4 +135,4 @@ module BaseHarvester
|
|
135
135
|
num_groups.map(&:join).join(',').reverse
|
136
136
|
end
|
137
137
|
|
138
|
-
end # module
|
138
|
+
end # module BaseDatafier
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'csv'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'basedatafier'
|
4
4
|
|
5
|
-
module
|
5
|
+
module CSVifier
|
6
6
|
|
7
|
-
include
|
7
|
+
include BaseDatafier
|
8
8
|
include FileProvider
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def included(base)
|
12
|
-
base.extend
|
12
|
+
base.extend CSVifierClassMethods
|
13
13
|
end
|
14
14
|
end # class << self
|
15
15
|
|
16
|
-
module
|
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,
|
83
|
-
@details_fields.merge!(
|
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:
|
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
|
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
|
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
|
526
|
+
end # module CSVifier
|
data/lib/datafy.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
|
-
require_relative 'datafy/
|
1
|
+
require_relative 'datafy/basedatafier'
|
2
2
|
require_relative 'datafy/fileprovider'
|
3
|
-
require_relative 'datafy/
|
3
|
+
require_relative 'datafy/csvifier'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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,34 @@
|
|
1
|
+
require 'datafy'
|
2
|
+
class Proto
|
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
|
+
proto = Proto.new
|
23
|
+
proto.harvest # assign values to properties, there are two main ways to accomplish this:
|
24
|
+
|
25
|
+
proto.id = 'XBCD' # standard assignment
|
26
|
+
proto.record( property: :attribute, value: "Hi there, I'm an attribute" ) # key-value 'details' assignment
|
27
|
+
|
28
|
+
proto.printCSVRecord # print the object's data as a CSV record
|
29
|
+
proto.printDetails # print the object's data as a set of key-valye (aka details) records
|
30
|
+
|
31
|
+
proto.persist # persist the object's attributes into CSV files,
|
32
|
+
# - one 'flat' file for normal records
|
33
|
+
# - one key-value file for the object's details
|
34
|
+
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.
|
4
|
+
version: 0.7.4
|
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-
|
11
|
+
date: 2024-03-31 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/
|
25
|
-
- lib/datafy/
|
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
|