artbase-importers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 721fb394f1bddd2d9daee7433856a6505b733d3aedc553dbe59cce8cc5624e2f
4
+ data.tar.gz: 6df5b15fe095fde357091944a8497eb51b1fbda0c6d6893782cf7a66e8b8653b
5
+ SHA512:
6
+ metadata.gz: 35151037dec36107f722c36e03184937103fe3d2c3cf82175a337a4a56d570c7a076e3afa413bd63b1d06b3a93d32a7b16fc1bf021f0992a559086c05428b029
7
+ data.tar.gz: 1b1eeb3d065407ed290c5850ae3314a025a95dd763499952aaf651912828f1071c04a9875667661a3f6eb1113458f7858e36e489d52dc10d5f65e602eb1d53f2
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2022-11-26
2
+
3
+ * Everything is new. First release
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/artbase-importers.rb
6
+ lib/artbase-importers/collection.rb
7
+ lib/artbase-importers/database.rb
8
+ lib/artbase-importers/importer.rb
9
+ lib/artbase-importers/version.rb
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # artbase-importers - artbase (SQL) database machinery 'n' support; build single-file SQLite artbase.dbs and more (via active-record machinery)
2
+
3
+
4
+ * home :: [github.com/pixelartexchange/artbase](https://github.com/pixelartexchange/artbase)
5
+ * bugs :: [github.com/pixelartexchange/artbase/issues](https://github.com/pixelartexchange/artbase/issues)
6
+ * gem :: [rubygems.org/gems/artbase-importers](https://rubygems.org/gems/artbase-importerss)
7
+ * rdoc :: [rubydoc.info/gems/artbase-importers](http://rubydoc.info/gems/artbase-importers)
8
+
9
+
10
+
11
+ ## Usage
12
+
13
+ To be done
14
+
15
+
16
+
17
+
18
+
19
+ ## License
20
+
21
+ The `artbase` scripts are dedicated to the public domain.
22
+ Use it as you please with no restrictions whatsoever.
23
+
24
+
25
+ ## Questions? Comments?
26
+
27
+ Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'hoe'
2
+ require './lib/artbase-importers/version.rb'
3
+
4
+
5
+ ###
6
+ # hack/ quick fix for broken intuit_values - overwrite with dummy
7
+ class Hoe
8
+ def intuit_values( input ); end
9
+ end
10
+
11
+
12
+ Hoe.spec 'artbase-importers' do
13
+
14
+ self.version = Artbase::Module::Importers::VERSION
15
+
16
+ self.summary = "artbase-importers - artbase (SQL) database machinery 'n' support; build single-file SQLite artbase.dbs and more (via active-record machinery)"
17
+ self.description = summary
18
+
19
+ self.urls = { home: 'https://github.com/pixelartexchange/artbase'}
20
+
21
+ self.author = 'Gerald Bauer'
22
+ self.email = 'wwwmake@googlegroups.com'
23
+
24
+ # switch extension to .markdown for gihub formatting
25
+ self.readme_file = 'README.md'
26
+ self.history_file = 'CHANGELOG.md'
27
+
28
+ self.extra_deps = [
29
+ ['artbase-cocos', '>= 0.0.1'],
30
+ ['sqlite3'],
31
+ ['activerecord'],
32
+ ]
33
+
34
+ self.licenses = ['Public Domain']
35
+
36
+ self.spec_extras = {
37
+ required_ruby_version: '>= 2.2.2'
38
+ }
39
+
40
+ end
@@ -0,0 +1,37 @@
1
+
2
+ module Artbase
3
+ class Base ## "abstract" Base collection - check -use a different name - why? why not?
4
+
5
+ def import( importer )
6
+
7
+ each_meta do |meta, id|
8
+ puts "==> #{id}"
9
+ pp meta.attributes
10
+ puts
11
+ h = importer.to_metadata( meta.attributes )
12
+ ## auto-add id (as intenger) - why? why not?
13
+ h[ 'id' ] = id
14
+
15
+
16
+ img = Image.read( "./#{@slug}/#{@width}x#{@height}/#{id}.png" )
17
+
18
+ image = "data:image/png;base64, "
19
+ image += Base64.strict_encode64( img.to_blob )
20
+
21
+ puts "image:"
22
+ puts image
23
+
24
+ rec = Database::Metadata.new( h )
25
+ rec.image = image
26
+
27
+ ## check for custom callback hooks
28
+ if importer.respond_to?( :before_save )
29
+ importer.before_save( rec )
30
+ end
31
+
32
+ rec.save!
33
+ end
34
+ end # method import
35
+
36
+ end # class Base
37
+ end # module Artbase
@@ -0,0 +1,66 @@
1
+
2
+ module Artbase
3
+
4
+ module Database
5
+
6
+ ####
7
+ # keep database models inside Database namespace for now
8
+ # (to avoid class with Artbase::Metadata) - why? why not?
9
+ class Metadata < ActiveRecord::Base
10
+ self.table_name = "metadata"
11
+ end
12
+
13
+
14
+ def self.create( spec )
15
+ ActiveRecord::Schema.define do
16
+ create_table :metadata do |t|
17
+
18
+ spec.each do |column|
19
+ column_name = column[0].to_sym
20
+ column_opts = column[1] || {}
21
+ column_type = (column[2] || 'string').to_sym
22
+
23
+ t.__send__( column_type, column_name, **column_opts )
24
+ end
25
+
26
+ t.string :image, null: false
27
+
28
+ t.timestamps
29
+ end
30
+ end # Schema.define
31
+ end # method self.create
32
+
33
+
34
+ def self.connect( database='./artbase.db' )
35
+
36
+ config = { adapter: 'sqlite3',
37
+ database: database,
38
+ }
39
+
40
+ puts "Connecting to db using settings: "
41
+ pp config
42
+ ActiveRecord::Base.establish_connection( config )
43
+ # ActiveRecord::Base.logger = Logger.new( STDOUT )
44
+
45
+ ## if sqlite3 add (use) some pragmas for speedups
46
+ ## note: if in memory database e.g. ':memory:' no pragma needed!!
47
+ ## try to speed up sqlite
48
+ ## see http://www.sqlite.org/pragma.html
49
+ con = ActiveRecord::Base.connection
50
+ con.execute( 'PRAGMA synchronous=OFF;' )
51
+ con.execute( 'PRAGMA journal_mode=OFF;' )
52
+ con.execute( 'PRAGMA temp_store=MEMORY;' )
53
+
54
+ end
55
+
56
+
57
+ def self.auto_migrate!( spec )
58
+ # first time? - auto-run db migratation, that is, create db tables
59
+ unless Metadata.table_exists?
60
+ create( spec )
61
+ end
62
+ end
63
+
64
+
65
+ end # module Database
66
+ end # module Artbase
@@ -0,0 +1,39 @@
1
+
2
+ module Artbase
3
+
4
+ class Importer ## use to import metadata into database
5
+
6
+ def self.read( path )
7
+ code = read_text( path )
8
+ parse( code )
9
+ end
10
+
11
+ def self.parse( code )
12
+ importer = new
13
+ importer.instance_eval( code )
14
+ importer
15
+ end
16
+
17
+
18
+ def slugify( str )
19
+ str = str.strip.downcase
20
+ str = str.gsub( /[ ]/, '_' )
21
+ str
22
+ end
23
+
24
+
25
+
26
+ ############
27
+ # defaults ("built-ins") method for to_metadata, etc.
28
+
29
+ def to_metadata( attributes )
30
+ h = {}
31
+ attributes.each do |key,value|
32
+ slug = slugify( key )
33
+ h[ slug ] = value
34
+ end
35
+ h
36
+ end
37
+ end # class Importer
38
+
39
+ end # module Artbase
@@ -0,0 +1,25 @@
1
+
2
+
3
+ module Artbase
4
+ module Module
5
+ module Importers
6
+ MAJOR = 0
7
+ MINOR = 0
8
+ PATCH = 1
9
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
10
+
11
+ def self.version
12
+ VERSION
13
+ end
14
+
15
+ def self.banner
16
+ "artbase-importers/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
17
+ end
18
+
19
+ def self.root
20
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
21
+ end
22
+
23
+ end # module Importers
24
+ end # module Module
25
+ end # module Artbase
@@ -0,0 +1,22 @@
1
+
2
+ require 'artbase-cocos'
3
+
4
+
5
+ ## add activerecord (database) machinery
6
+ require 'sqlite3'
7
+ require 'active_record'
8
+
9
+
10
+
11
+ ## our own code
12
+ require_relative 'artbase-importers/version'
13
+ require_relative 'artbase-importers/database'
14
+ require_relative 'artbase-importers/importer'
15
+ require_relative 'artbase-importers/collection'
16
+
17
+
18
+
19
+
20
+
21
+
22
+ puts Artbase::Module::Importers.banner # say hello
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artbase-importers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: artbase-cocos
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '7'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '4.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '7'
75
+ - !ruby/object:Gem::Dependency
76
+ name: hoe
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.23'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.23'
89
+ description: artbase-importers - artbase (SQL) database machinery 'n' support; build
90
+ single-file SQLite artbase.dbs and more (via active-record machinery)
91
+ email: wwwmake@googlegroups.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files:
95
+ - CHANGELOG.md
96
+ - Manifest.txt
97
+ - README.md
98
+ files:
99
+ - CHANGELOG.md
100
+ - Manifest.txt
101
+ - README.md
102
+ - Rakefile
103
+ - lib/artbase-importers.rb
104
+ - lib/artbase-importers/collection.rb
105
+ - lib/artbase-importers/database.rb
106
+ - lib/artbase-importers/importer.rb
107
+ - lib/artbase-importers/version.rb
108
+ homepage: https://github.com/pixelartexchange/artbase
109
+ licenses:
110
+ - Public Domain
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options:
114
+ - "--main"
115
+ - README.md
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 2.2.2
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.3.7
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: artbase-importers - artbase (SQL) database machinery 'n' support; build single-file
133
+ SQLite artbase.dbs and more (via active-record machinery)
134
+ test_files: []