Class: Artbase::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/artbase/tool.rb

Class Method Summary collapse

Class Method Details

.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_imagesObject



153
154
155
156
# File 'lib/artbase/tool.rb', line 153

def self.convert_images
  puts "==> convert images"
  @collection.convert_images( overwrite: false )
end

.download_images(offset:) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/artbase/tool.rb', line 189

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



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/artbase/tool.rb', line 176

def self.download_meta( offset: )
    puts "==> download meta"

    range = if offset
              @collection._range( offset: offset )
            else
              @collection._range
            end

    @collection.download_meta( range )
end

.dump_attributesObject



165
166
167
168
# File 'lib/artbase/tool.rb', line 165

def self.dump_attributes
  puts "==> dump attributes"
  @collection.dump_attributes
end

.export_attributesObject



170
171
172
173
# File 'lib/artbase/tool.rb', line 170

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
137
138
139
140
141
142
143
144
145
146
# File 'lib/artbase/tool.rb', line 15

def self.main( args=ARGV )
  puts "==> welcome to collection tool with args:"
  pp args


  options = { faster: false,
              mirror: false,
            }

  parser = OptionParser.new do |opts|

    opts.on("--offset NUM", Integer,
            "Start counting at offset (default: 0)") do |num|
        options[ :offset]  = num
    end

    opts.on("--limit NUM", Integer,
            "Limit collection (default: ∞)") do |num|
        options[ :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
        options[ :faster ] = true
    end

    opts.on( "--mirror", "Mirror (or flip) images (default: false)" ) do
        options[ :mirror ] = true
    end


    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end
  end

  parser.parse!( args )
  puts "options:"
  pp options

  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}<..."
     config = read_yaml( path )

     ## todo - use TokenCollection.read( ) or such -- why? why not?
     ##           or TokenCollection.build( hash ) ?? - why? why not?
     self.collection = TokenCollection.new(
       config['slug'],
       config['count'],
       token_base: config['token_base'],
       image_base: config['image_base'],
       format: config['format'],
       source: config['source'],
       offset: config['offset'] || 0
     )
  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 )
         download_meta
       elsif ['i', 'img', 'image', 'images'].include?( subcommand )
         download_images
       end
    else
      download_meta
      download_images
    end
  elsif ['p', 'px', 'pix', 'pixel', 'pixelate'].include?( command )
    pixelate( offset: options[ :offset],
              faster: options[ :faster] )
  elsif ['m', 'meta'].include?( command )
    download_meta( offset: options[ :offset] )
  elsif ['i', 'img', 'image', 'images'].include?( command )
    download_images( offset: options[ :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 ['c', 'composite'].include?( command )
    make_composite( limit: options[ :limit],
                    mirror: options[ :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



148
149
150
151
# File 'lib/artbase/tool.rb', line 148

def self.make_composite( limit: nil, mirror: false )
  puts "==> make composite"
  @collection.make_composite( limit: limit, mirror: mirror )
end

.make_stripObject



159
160
161
162
# File 'lib/artbase/tool.rb', line 159

def self.make_strip
  puts "==> make strip"
  @collection.make_strip
end

.pixelate(offset:, faster:) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/artbase/tool.rb', line 202

def self.pixelate( offset:,
                   faster: )
  puts "==> pixelate"

  range = if offset
            @collection._range( offset: offset )
          else
            @collection._range
          end

  @collection.pixelate( range, faster: faster )
end