Class: Panoramix::Plugin::Wget

Inherits:
Base
  • Object
show all
Defined in:
lib/panoramix/plugin/wget.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#shell

Constructor Details

#initialize(dst, src, flags) ⇒ Wget

Returns a new instance of Wget.



12
13
14
15
16
# File 'lib/panoramix/plugin/wget.rb', line 12

def initialize(dst, src, flags)
	@dst = dst
	@src = src
	@flags = flags
end

Instance Attribute Details

#dstObject (readonly)

Returns the value of attribute dst.



8
9
10
# File 'lib/panoramix/plugin/wget.rb', line 8

def dst
  @dst
end

#flagsObject (readonly)

Returns the value of attribute flags.



10
11
12
# File 'lib/panoramix/plugin/wget.rb', line 10

def flags
  @flags
end

#srcObject (readonly)

Returns the value of attribute src.



9
10
11
# File 'lib/panoramix/plugin/wget.rb', line 9

def src
  @src
end

Instance Method Details

#cleanObject

Action clean fot this task



38
39
40
# File 'lib/panoramix/plugin/wget.rb', line 38

def clean
	shell "rm -f #{@dst}"
end

#created?Boolean

Has this instance already been created

Returns:

  • (Boolean)


33
34
35
# File 'lib/panoramix/plugin/wget.rb', line 33

def created?
	File.exists?(@dst)
end

#needed?(timestamps) ⇒ Boolean

When this instance needs to be executed

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/panoramix/plugin/wget.rb', line 27

def needed? timestamps
	return true if !created?
	File.mtime(@dst) < timestamp
end

#run_defaultObject

Default action for this task



43
44
45
# File 'lib/panoramix/plugin/wget.rb', line 43

def run_default
	shell "wget -nv #{@flags} #{@src} -O #{@dst}"
end

#timestampObject

Return current timestamp



19
20
21
22
23
24
# File 'lib/panoramix/plugin/wget.rb', line 19

def timestamp
	return Time.at 0 unless created?
	remote_time = shell("wget #{@flags} --spider -S #{@src} 2>&1 | grep Last-Modified", true)[:out]
    remote_time = remote_time.split("Last-Modified: ").last
    remote_time = Time.parse(remote_time)
end