Class: AppleEpf::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_epf/main.rb

Direct Known Subclasses

Full, Incremental

Defined Under Namespace

Modules: BaseActions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filedate, files_matrix = nil, store_dir = nil, keep_tbz_after_extract = nil) ⇒ Main

Returns a new instance of Main.



8
9
10
11
12
13
# File 'lib/apple_epf/main.rb', line 8

def initialize(filedate, files_matrix = nil, store_dir = nil, keep_tbz_after_extract = nil)
  @filedate = filedate
  @files_matrix = files_matrix || AppleEpf.files_matrix
  @store_dir = store_dir
  @keep_tbz_after_extract = !!keep_tbz_after_extract || AppleEpf.keep_tbz_after_extract
end

Instance Attribute Details

#downloaderObject (readonly)

Returns the value of attribute downloader.



5
6
7
# File 'lib/apple_epf/main.rb', line 5

def downloader
  @downloader
end

#filedateObject (readonly)

Returns the value of attribute filedate.



5
6
7
# File 'lib/apple_epf/main.rb', line 5

def filedate
  @filedate
end

#files_matrixObject (readonly)

Returns the value of attribute files_matrix.



5
6
7
# File 'lib/apple_epf/main.rb', line 5

def files_matrix
  @files_matrix
end

#keep_tbz_after_extractObject

Returns the value of attribute keep_tbz_after_extract.



6
7
8
# File 'lib/apple_epf/main.rb', line 6

def keep_tbz_after_extract
  @keep_tbz_after_extract
end

#store_dirObject

Returns the value of attribute store_dir.



6
7
8
# File 'lib/apple_epf/main.rb', line 6

def store_dir
  @store_dir
end

Class Method Details

.get_current_listObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apple_epf/main.rb', line 15

def self.get_current_list
    curl = Curl::Easy.new(self.current_url)
    curl.http_auth_types = :basic
    curl.username = AppleEpf.apple_id
    curl.password = AppleEpf.apple_password
    curl.follow_location = true
    curl.max_redirects = 5
    curl.perform
    body = curl.body_str

    files =  Nokogiri::HTML(body).xpath("//td/a").map(&:text).select{|s| s=~/.*tbz$/}

    files.inject({}) do |all, e|
      e.match(/([a-z]*)(\d*.tbz)/)
      all[$1] = {}
      all[$1][:base] = $2.chomp(".tbz")
      all[$1][:full_url] = self.current_url + "/#{$1}#{$2}"
      all
    end
end