datafy 0.7.5 → 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 +4 -4
- data/lib/datafy/BaseDatafier.rb +2 -10
- data/lib/datafy/CSVifier.rb +5 -0
- data/lib/datafy/FileProvider.rb +2 -2
- data/lib/datafy.rb +3 -3
- data/lib/resources/DatafyDemo.rb +82 -0
- data/lib/resources/Proto.rb +1 -1
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7db53eae7e64ecd16eaa09db8451804d45221a80aa561f4fad07f751f16dffc
|
|
4
|
+
data.tar.gz: 371ec865101714566cd6bb56b701c4bb9ae17318c3ae0e964caecf6d6bef08a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cb7cf2bb2e101369f91d425d2b6c0fdc8f8796e5a77547c74a3c862579e195d47f107603572beaf3fc524bec4b9234f28b452b775bf47711707fa4c709432f2
|
|
7
|
+
data.tar.gz: 265a8feeb867f8d01be900049f9ce85939ce30ed986fbfb70bbea3b8624c21bc36b16bdffb98dc9c26f8fb628cc6172877cb8f8c8b3e0a2a2d66679a8e87a4de
|
data/lib/datafy/BaseDatafier.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# print "
|
|
1
|
+
# print "Loading: #{__FILE__}"
|
|
2
2
|
|
|
3
3
|
require 'date'
|
|
4
4
|
require 'logger'
|
|
@@ -55,7 +55,7 @@ module BaseDatafier
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def logFileName
|
|
58
|
-
@logFileName ||= FileProvider.getDataFileName("#{self
|
|
58
|
+
@logFileName ||= FileProvider.getDataFileName("#{self}.log")
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def attr_fields fields
|
|
@@ -95,14 +95,6 @@ module BaseDatafier
|
|
|
95
95
|
attr_fields fields
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
# def register_details_fields fields
|
|
99
|
-
# return if fields.nil?
|
|
100
|
-
# @details_fields = {} if @details_fields.nil?
|
|
101
|
-
# @details_fields.merge!(fields)
|
|
102
|
-
# @details_fields.merge!(BASE_HARVEST_DATA_FIELDS)
|
|
103
|
-
# attr_fields @details_fields
|
|
104
|
-
# end
|
|
105
|
-
|
|
106
98
|
def details_fields
|
|
107
99
|
# puts "#{self.class}::#{__method__}"
|
|
108
100
|
if @details_fields.nil?
|
data/lib/datafy/CSVifier.rb
CHANGED
data/lib/datafy/FileProvider.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# puts "
|
|
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.
|
|
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 "\
|
|
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
|
|
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
|
|
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."
|
data/lib/resources/Proto.rb
CHANGED
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:
|
|
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:
|
|
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:
|
|
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.
|