Class: Artbase::Tool
- Inherits:
-
Object
- Object
- Artbase::Tool
- Defined in:
- lib/artbase/tool.rb
Class Method Summary collapse
- .build_database ⇒ Object
- .collection=(value) ⇒ Object
- .convert_images ⇒ Object
- .download_images(offset:) ⇒ Object
- .download_meta(offset:) ⇒ Object
- .dump_attributes ⇒ Object
- .export_attributes ⇒ Object
- .main(args = ARGV) ⇒ Object
- .make_composite(limit: nil, mirror: false) ⇒ Object
- .make_strip ⇒ Object
- .pixelate(offset:, faster:) ⇒ Object
Class Method Details
.build_database ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/artbase/tool.rb', line 140 def self.build_database puts "===> build database" ### note. load database "heavy" machinery only on-demand ## make it a "soft" dependency for now - why? why not? require 'artbase-importers' slug = @collection.slug importer = Importer.read( "./#{slug}/build.rb" ) columns = importer. pp columns Database.connect( "./#{slug}/artbase.db" ) Database.auto_migrate!( columns ) @collection.import( importer ) end |
.collection=(value) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/artbase/tool.rb', line 7 def self.collection=(value) puts " setting collection to:" pp value @collection = value end |
.convert_images ⇒ Object
168 169 170 171 |
# File 'lib/artbase/tool.rb', line 168 def self.convert_images puts "==> convert images" @collection.convert_images( overwrite: false ) end |
.download_images(offset:) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/artbase/tool.rb', line 204 def self.download_images( offset: ) puts "==> download images" range = if offset @collection._range( offset: offset ) else @collection._range end @collection.download_images( range ) end |
.download_meta(offset:) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/artbase/tool.rb', line 191 def self.( offset: ) puts "==> download meta" range = if offset @collection._range( offset: offset ) else @collection._range end @collection.( range ) end |
.dump_attributes ⇒ Object
180 181 182 183 |
# File 'lib/artbase/tool.rb', line 180 def self.dump_attributes puts "==> dump attributes" @collection.dump_attributes end |
.export_attributes ⇒ Object
185 186 187 188 |
# File 'lib/artbase/tool.rb', line 185 def self.export_attributes puts "==> export attributes" @collection.export_attributes end |
.main(args = ARGV) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/artbase/tool.rb', line 15 def self.main( args=ARGV ) puts "==> welcome to collection tool with args:" pp args = { faster: false, mirror: false, } parser = OptionParser.new do |opts| opts.on("--offset NUM", Integer, "Start counting at offset (default: 0)") do |num| [ :offset] = num end opts.on("--limit NUM", Integer, "Limit collection (default: ∞)") do |num| [ :limit] = num end ## todo/fix: unsupported argument type: Range ## opts.on("--range RANGE", Range, ## "Range of collection (default: 0..∞") do |range| ## options[ :range] = range ## end opts.on( "--faster", "Use faster (optional) pixelate binary (default: false)") do [ :faster ] = true end opts.on( "--mirror", "Mirror (or flip) images (default: false)" ) do [ :mirror ] = true end opts.on("-h", "--help", "Prints this help") do puts opts exit end end parser.parse!( args ) puts "options:" pp puts "args:" pp args if args.size < 2 puts "!! ERROR - no command found - use <collection> <command>..." puts "" exit end name = args[0] ## todo/check - use collection_name/slug or such? command = args[1] subcommand = args[2] if File.exist?( "./#{name}/collection.yml" ) path = "./#{name}/collection.yml" puts "==> reading collection config >#{path}<..." self.collection = TokenCollection.read( path ) else ## todo/check: keep config.rb alternate name - why? why not? ## or use collection.rb only ??? path = if File.exist?( "./#{name}/config.rb" ) "./#{name}/config.rb" else "./#{name}/collection.rb" end puts "==> reading collection config >#{path}<..." ## note: assume for now global const COLLECTION gets set/defined!!! ## use/change to a script/dsl loader/eval later!!! load( path ) ## pp COLLECTION ## configure collection (note: requires self) self.collection = COLLECTION end if ['d','dl','down', 'download'].include?( command ) if subcommand if ['m', 'meta'].include?( subcommand ) elsif ['i', 'img', 'image', 'images'].include?( subcommand ) download_images end else download_images end elsif ['p', 'px', 'pix', 'pixel', 'pixelate'].include?( command ) pixelate( offset: [ :offset], faster: [ :faster] ) elsif ['m', 'meta'].include?( command ) ( offset: [ :offset] ) elsif ['i', 'img', 'image', 'images'].include?( command ) download_images( offset: [ :offset] ) elsif ['conv', 'convert'].include?( command ) convert_images elsif ['a', 'attr', 'attributes'].include?( command ) dump_attributes elsif ['x', 'exp', 'export'].include?( command ) export_attributes elsif ['b', 'build'].include?( command ) build_database elsif ['c', 'composite'].include?( command ) make_composite( limit: [ :limit], mirror: [ :mirror ]) elsif ['strip'].include?( command ) make_strip elsif ['t', 'test'].include?( command ) puts " testing, testing, testing" else puts "!! ERROR - unknown command >#{command}<, sorry" end puts "bye" end |
.make_composite(limit: nil, mirror: false) ⇒ Object
163 164 165 166 |
# File 'lib/artbase/tool.rb', line 163 def self.make_composite( limit: nil, mirror: false ) puts "==> make composite" @collection.make_composite( limit: limit, mirror: mirror ) end |
.make_strip ⇒ Object
174 175 176 177 |
# File 'lib/artbase/tool.rb', line 174 def self.make_strip puts "==> make strip" @collection.make_strip end |
.pixelate(offset:, faster:) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/artbase/tool.rb', line 217 def self.pixelate( offset:, faster: ) puts "==> pixelate" range = if offset @collection._range( offset: offset ) else @collection._range end @collection.pixelate( range, faster: faster ) end |