Module: Vimpack::Utils::Vimscripts::ClassMethods

Defined in:
lib/vimpack/utils/vimscripts.rb

Instance Method Summary collapse

Instance Method Details

#get_vimscript(name) ⇒ Object



47
48
49
50
51
52
# File 'lib/vimpack/utils/vimscripts.rb', line 47

def get_vimscript(name)
  results = vimscripts.delete_if do |vimscript|
    !(vimscript['n'] == name)
  end
  normalize_vimscript(results.first) rescue nil
end

#normalize_results(limit, offset, results) ⇒ Object



28
29
30
31
32
# File 'lib/vimpack/utils/vimscripts.rb', line 28

def normalize_results(limit, offset, results)
  results[offset..limit-1].map do |script|
    normalize_vimscript(script)
  end
end

#normalize_vimscript(script) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/vimpack/utils/vimscripts.rb', line 54

def normalize_vimscript(script)
  { :name => script['n'], :type => script['t'],
    :description => script['s'], :script_version => script['rv'],
    :author => script['ra'], :author_email => script['re'],
    :repo_owner => 'vim-scripts'
  }
end

#search_for_string(q, results) ⇒ Object



40
41
42
43
44
45
# File 'lib/vimpack/utils/vimscripts.rb', line 40

def search_for_string(q, results)
  q = q.downcase
  results.delete_if do |vimscript|
    !(vimscript['n'].downcase.include?(q) or vimscript['s'].downcase.include?(q))
  end
end

#search_for_type(types, results) ⇒ Object



34
35
36
37
38
# File 'lib/vimpack/utils/vimscripts.rb', line 34

def search_for_type(types, results)
  results.delete_if do |vimscript|
    !types.include?(vimscript['t'])
  end
end

#search_vimscripts(q, types = [], limit = 10, offset = 0) ⇒ Object



22
23
24
25
26
# File 'lib/vimpack/utils/vimscripts.rb', line 22

def search_vimscripts(q, types = [], limit = 10, offset = 0)
  results = q.nil? ? vimscripts : search_for_string(q, vimscripts)
  results = types.empty? ? results : search_for_type(types, results)
  normalize_results(limit, offset, results)
end

#vimscriptsObject



16
17
18
19
20
# File 'lib/vimpack/utils/vimscripts.rb', line 16

def vimscripts
  # {"n"=>"test.vim", "t"=>"utility", "s"=>"example utility script file -- used for testing vimonline", "rv"=>"1.0", "rd"=>"2001-05-28", "ra"=>"Scott Johnston", "re"=>"[email protected]"}
  @vimscripts ||= Yajl.load(wrap_open(vimscripts_url))
  @vimscripts.clone
end

#vimscripts_urlObject



12
13
14
# File 'lib/vimpack/utils/vimscripts.rb', line 12

def vimscripts_url
  'http://vim-scripts.org/api/scripts_recent.json'
end