Module: Eyecon

Defined in:
lib/eyecon/cli.rb,
lib/eyecon/main.rb,
lib/eyecon/version.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

CACHE_FILE =
File.expand_path("../output/cache.html", __dir__)
INDEX_FILE =
File.expand_path("../output/index.html", __dir__)
TEMPLATE_FILE =
File.expand_path("template.html", __dir__)
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.cacheObject



20
21
22
23
24
25
# File 'lib/eyecon/main.rb', line 20

def cache
  doc = Nokogiri::HTML(File.open(CACHE_FILE))
  openfile(doc)
rescue StandardError => e
  puts e.message
end

.openfile(doc) ⇒ Object



45
46
47
48
49
# File 'lib/eyecon/main.rb', line 45

def openfile(doc)
  scrape(doc).then { |a| render(a) }
  os = RbConfig::CONFIG["host_os"]
  exec("open", INDEX_FILE) if os.include?("darwin")
end

.render(content) ⇒ Object



39
40
41
42
43
# File 'lib/eyecon/main.rb', line 39

def render(content)
  template = ERB.new(File.read(TEMPLATE_FILE))
  t = template.result_with_hash(content: content)
  File.write(INDEX_FILE, t)
end

.scrape(doc) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/eyecon/main.rb', line 27

def scrape(doc)
  res = []
  doc.css("div .Vpfmgd").each do |link|
    a = []
    a << link.css("img")[0]["data-src"]
    a << link.css("a div")[0].text
    a << link.css("a div")[1].text
    res << a
  end
  res
end

.search(word) ⇒ Object



14
15
16
17
18
# File 'lib/eyecon/main.rb', line 14

def search(word)
  doc = Nokogiri::HTML(URI.parse("https://play.google.com/store/search?q=#{word}&c=apps").open)
  File.write(CACHE_FILE, doc)
  openfile(doc)
end