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

.download_images(offset:) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/artbase/tool.rb', line 140

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



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/artbase/tool.rb', line 127

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



116
117
118
119
# File 'lib/artbase/tool.rb', line 116

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

.export_attributesObject



121
122
123
124
# File 'lib/artbase/tool.rb', line 121

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
# File 'lib/artbase/tool.rb', line 15

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

  options = { }
  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("-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]


  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


  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] )
  elsif ['m', 'meta'].include?( command )
    download_meta( offset: options[ :offset] )
  elsif ['i', 'img', 'image', 'images'].include?( command )
    download_images( offset: options[ :offset] )
  elsif ['a', 'attr', 'attributes'].include?( command )
    dump_attributes
  elsif ['x', 'exp', 'export'].include?( command )
    export_attributes
  elsif ['c', 'composite'].include?( command )
    make_composite
  elsif ['t', 'test'].include?( command )
     puts "  testing, testing, testing"
  else
    puts "!! ERROR - unknown command >#{command}<, sorry"
  end

  puts "bye"
end

.make_compositeObject



111
112
113
114
# File 'lib/artbase/tool.rb', line 111

def self.make_composite
  puts "==> make composite"
  @collection.make_composite
end

.pixelate(offset:) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/artbase/tool.rb', line 152

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

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

  @collection.pixelate( range )
end