Class: PapyTools::CommandeCreate

Inherits:
Commande
  • Object
show all
Defined in:
lib/papy-tools/commande.rb

Instance Method Summary collapse

Methods inherited from Commande

instance

Constructor Details

#initializeCommandeCreate

Returns a new instance of CommandeCreate.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/papy-tools/commande.rb', line 143

def initialize
    @template="default.html.erb"
    @opts = GetoptLong.new([ '--club', '-c', GetoptLong::NO_ARGUMENT ],
                          [ '--pays', '-a', GetoptLong::NO_ARGUMENT ],	
                          ['--ligue','-l',GetoptLong::REQUIRED_ARGUMENT ],
                          ['--premiers','-p',GetoptLong::REQUIRED_ARGUMENT ],
                          ['--departage','-d',GetoptLong::NO_ARGUMENT],
                          ['--template','-t',GetoptLong::REQUIRED_ARGUMENT ],
                          ['--liste','-L',GetoptLong::REQUIRED_ARGUMENT],
                          ['--output','-o',GetoptLong::REQUIRED_ARGUMENT],
                          ['--invisibles','-i',GetoptLong::REQUIRED_ARGUMENT]

	  )
    @filtres={}
    @invisibles={:ligue=>false,:categorie=>false,:club=>false,:pays=>false,:departages=>false}
end

Instance Method Details

#filter_erbObject



171
172
173
174
175
176
177
178
179
180
# File 'lib/papy-tools/commande.rb', line 171

def filter_erb()
    begin
      io=open(File.join("template",@template))
    rescue Exception
      puts "template non trouvé:#{@template}"
      exit 0
    end
    view= ERB.new(io.readlines.join("\n") , 0, "%<>")
    @content=view.result(@presentation.get_binding)
end

#input(input) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/papy-tools/commande.rb', line 188

def input(input)
    begin
      io=open(input)
    rescue
      puts "fichier non trouvé:#{input}"
      exit 0
    end
    content=io.readlines.join("\n")
    Hpricot(content, :xhtml_strict => true)

end

#name_output_fileObject



217
218
219
220
221
222
# File 'lib/papy-tools/commande.rb', line 217

def name_output_file
    @output_file=File.join("output",@output_file)
    output_part=@template.split(".")
    output_type_file=output_part[1] if output_part.length == 3
    @output_file=@output_file+"."+output_type_file if output_type_file
end

#outputObject



182
183
184
185
186
# File 'lib/papy-tools/commande.rb', line 182

def output()
    File.open(@output_file,"w") do |f|
        f.puts @content
    end
end

#parametresObject



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/papy-tools/commande.rb', line 224

def parametres

    @opts.each do |opt, arg|
         case opt
           when '--pays'
              @filtres[:pays]=arg
           when '--ligue'
              @filtres[:ligue]=arg
           when '--premiers'
              @filtres[:premiers]=arg
              p "filtre premiers"
           when '--departage'
              options[:departage]=false
           when '--template'
               @template=arg
           when "--liste"
               @liste=arg
           when "--output"
               @output=arg
           when "--invisibles"
               set_invisible(arg)
         end
    end
end

#run(options = {}) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/papy-tools/commande.rb', line 160

def run(options={})
  ressource=ARGV[1]
  if URI.extract(ressource).empty?
      CommandeCreateWithHTM.instance.run()
  else
      CommandeCreateWithSite.instance.run()
  end

end

#set_invisible(arg) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/papy-tools/commande.rb', line 200

def set_invisible(arg)
    arg.split("").each do |c|
        case c
        when 'l'
            @invisibles[:ligue]=true
        when 'p'
            @invisibles[:pays]=true
        when 'd'
            @invisibles[:departages]=true
        when 'c'
            @invisibles[:club]=true
        when 'a'
            @invisibles[:categorie]=true
        end
    end
end