Class: DailyTrending::App

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_urlObject

Returns the value of attribute app_url.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def app_url
  @app_url
end

#con_ratingObject

Returns the value of attribute con_rating.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def con_rating
  @con_rating
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def description
  @description
end

#devObject

Returns the value of attribute dev.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def dev
  @dev
end

#dev_urlObject

Returns the value of attribute dev_url.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def dev_url
  @dev_url
end

#genreObject

Returns the value of attribute genre.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def genre
  @genre
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def price
  @price
end

#rate_cntObject

Returns the value of attribute rate_cnt.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def rate_cnt
  @rate_cnt
end

#ratingObject

Returns the value of attribute rating.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def rating
  @rating
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/daily_trending/app.rb', line 2

def title
  @title
end

Class Method Details

.allObject



34
35
36
# File 'lib/daily_trending/app.rb', line 34

def self.all
  @@all
end

.new_from_index(a) ⇒ Object

def self.make_apps



13
14
15
16
17
18
19
20
21
22
# File 'lib/daily_trending/app.rb', line 13

def self.new_from_index(a)
    app = self.new
    app.title = a.css('a.title').attribute('title').value
    app.dev = a.css('a.subtitle').attribute('title').value
    app.dev_url = ("https://play.google.com" + a.css('a.subtitle').attribute('href').value)
    app.app_url = ("https://play.google.com" + a.css('a.title').attribute('href').value)
    app.rating = a.css('div.tiny-star').attribute('aria-label').value.strip.slice(/\d.\S/)<<"/5 Stars"
    app.price = a.at_css('span.display-price').text
    app.exist? ? all.freeze : app.save
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/daily_trending/app.rb', line 25

def exist?
  self.class.all.any?{|ap| ap.title == self.title}
end

#make_app(xml_info) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/daily_trending/app.rb', line 39

def make_app(xml_info)
  page = xml_info
  self.genre = page.css('a.document-subtitle.category').text
  self.description = page.css('div.show-more-content.text-body').text
  self.con_rating = page.css('span.document-subtitle.content-rating-title').text
  self.rate_cnt = page.css('span.rating-count').text
end

#saveObject



30
31
32
# File 'lib/daily_trending/app.rb', line 30

def save
  @@all << self
end