Class: Applist::Apps

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#avg_ratingObject

Returns the value of attribute avg_rating.



2
3
4
# File 'lib/applist/apps.rb', line 2

def avg_rating
  @avg_rating
end

#categoryObject

Returns the value of attribute category.



2
3
4
# File 'lib/applist/apps.rb', line 2

def category
  @category
end

#descObject

Returns the value of attribute desc.



2
3
4
# File 'lib/applist/apps.rb', line 2

def desc
  @desc
end

Returns the value of attribute link.



2
3
4
# File 'lib/applist/apps.rb', line 2

def link
  @link
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/applist/apps.rb', line 2

def name
  @name
end

Class Method Details



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/applist/apps.rb', line 4

def self.popular
  app_page = Nokogiri::HTML(open("https://www.apple.com/itunes/charts/free-apps/"))
  apps = []

    app_page.css("div.section-content li").each do |app|
      
      @app_obj = { name: '', category: '', link: '', desc: '', avg_rating: '' }
      @app_obj[:name] = [app.css("h3 a").text]
      @app_obj[:category] = [app.css("h4 a").text]
      @app_obj[:link] = [app.css("a").attribute("href").value]
      
      doc = Nokogiri::HTML(open(@app_obj[:link][0], 'User-Agent' => 'firefox'))
      @app_obj[:desc] = doc.css(".section__description").text
      @app_obj[:avg_rating] = doc.css(".we-customer-ratings__averages__display").text
      
      apps << @app_obj
    end

  apps
end