Class: SafariPlist

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = "", access_time = "", visit_count = "", title = "") ⇒ SafariPlist

Returns a new instance of SafariPlist.



7
8
9
10
11
12
# File 'lib/safari_plist.rb', line 7

def initialize(url="",access_time="",visit_count="",title="")
  @url =url
  @access_time = (Time.utc(2001,"jan",1,0,0,0)+access_time.to_f).to_s
  @visit_count = visit_count
  @title = title
end

Instance Attribute Details

#access_timeObject (readonly)

Returns the value of attribute access_time.



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

def access_time
  @access_time
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

#visit_countObject (readonly)

Returns the value of attribute visit_count.



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

def visit_count
  @visit_count
end

Class Method Details

.get_history(file_name, plutil_path = "plutil") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/safari_plist.rb', line 14

def self.get_history(file_name,plutil_path="plutil")
    result = ""
    @histories = []
   if !file_name.nil?
     result = `#{plutil_path} -i #{file_name}`
     doc = Hpricot.parse(result)  
     @histories = self.process_history(doc)
   else
      puts "Please enter file name"
      return -1
   end
   @histories 
end

.process_history(doc) ⇒ Object



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
# File 'lib/safari_plist.rb', line 28

def self.process_history(doc)
  safari_history = []
  doc.get_elements_by_tag_name("array").first.get_elements_by_tag_name("dict").each do |hp_doc|
    browsing_url = ""
    access_time = ""
    no_of_visit = ""
    title =""
    hp_doc.get_elements_by_tag_name("string").each do |value|
      string_value = value.innerText.match(/((\w+):\/\/(.+))/)
      if !string_value.nil?
        browsing_url = string_value[0]
      elsif !value.previous_node.nil? && !value.previous_node.previous_node.nil?   
        node_text= value.previous_node.previous_node.innerText 
        access_time = value.innerText if node_text == "lastVisitedDate"
        title = value.innerText if node_text == "title"    
      end
    end 
    hp_doc.get_elements_by_tag_name("integer").each do |visit_count|
      if !visit_count.previous_node.nil? && !visit_count.previous_node.previous_node.nil? && visit_count.previous_node.previous_node.innerText == "visitCount"
        no_of_visit = visit_count.innerText 
      end
    end
    safari_history << SafariPlist.new(browsing_url,access_time,no_of_visit,title)
  end
  safari_history
end