Class: Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_doc/data/data_processor.rb

Class Method Summary collapse

Class Method Details

.find_fav(name) ⇒ Object

Find Fav==============================


52
53
54
55
56
# File 'lib/ruby_doc/data/data_processor.rb', line 52

def self.find_fav(name) 
  doc = $DocDB.find{|doc| doc.name == name}
  
  load_doc(doc) 
end

.lastObject



15
16
17
# File 'lib/ruby_doc/data/data_processor.rb', line 15

def self.last 
  UI.browse_list($DocDB[1500..$DocDB.count], "Last")
end

.load_doc(doc) ⇒ Object

Load Doc==============================


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_doc/data/data_processor.rb', line 19

def self.load_doc(doc) 
  if !doc.nil?
    Scraper.load_class_doc(doc) if doc.type == "Class" || doc.type == "Module"
    Scraper.load_method_doc(doc) if doc.type == "Method"
    
    UI.display_class(doc) if doc.type == "Class" || doc.type == "Module"
    UI.display_method(doc) if doc.type == "Method"
  else 
    UI.nil_error
  end
end

.page1Object

Browse Pages============================


3
4
5
# File 'lib/ruby_doc/data/data_processor.rb', line 3

def self.page1 
  UI.browse_list($DocDB[0..499], "Page1")
end

.page2Object



7
8
9
# File 'lib/ruby_doc/data/data_processor.rb', line 7

def self.page2 
  UI.browse_list($DocDB[500..999], "Page2")
end

.page3Object



11
12
13
# File 'lib/ruby_doc/data/data_processor.rb', line 11

def self.page3 
  UI.browse_list($DocDB[1000..1499], "Page3")
end

.reset_favsObject

Reset Favs=============================


58
59
60
61
62
# File 'lib/ruby_doc/data/data_processor.rb', line 58

def self.reset_favs 
  open("#{fav_dir}", File::TRUNC) {}
  
  UI.reset_favs_message
end

.save(doc) ⇒ Object

Save Doc==============================


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_doc/data/data_processor.rb', line 31

def self.save(doc) 
  # if entry does not exist write else inform entry exist
  if uniq(doc) 
    File.open("#{fav_dir}", "a"){|l| l.puts doc.name}
    puts "\r"
    print doc.name.cyan + " Saved!".light_cyan
    
    UI.display_class_control(doc)
  else 
    puts "\r"
    print doc.name.cyan + " Already Saved!".light_red
    
    UI.display_class_control(doc)
  end
end

.search(name) ⇒ Object

SEARCH===============================


64
65
66
# File 'lib/ruby_doc/data/data_processor.rb', line 64

def self.search(name)
  $DocDB.find_all{|doc| doc.name.downcase.include?(name)}
end

.uniq(doc) ⇒ Object

save(doc) Helper Method



47
48
49
50
# File 'lib/ruby_doc/data/data_processor.rb', line 47

def self.uniq(doc) # save(doc) Helper Method 
  # read => uniq boolean
  File.open("#{fav_dir}").none?{|l| l.chomp == doc.name}
end