class PlayStoreInfo::AppParser

Public Class Methods

new(id, body) click to toggle source
# File lib/play_store_info/app_parser.rb, line 9
def initialize(id, body)
  @id = id
  @body = body

  scrape_data

  self
end

Private Instance Methods

read_artwork() click to toggle source
# File lib/play_store_info/app_parser.rb, line 33
def read_artwork
  url = @body.xpath('//img[@itemprop="image"]/@src').first&.value&.strip || ''

  # add the HTTP protocol if the image source is lacking http:// because it starts with //
  url.match(%r{^https?:\/\/}).nil? ? "http://#{url.gsub(%r{\A\/\/}, '')}" : url
end
read_description() click to toggle source
# File lib/play_store_info/app_parser.rb, line 40
def read_description
  description = @body.xpath('//div[@itemprop="description"]').first&.inner_html&.strip

  description.nil? ? '' : Sanitize.fragment(description).strip
end
read_id() click to toggle source
# File lib/play_store_info/app_parser.rb, line 20
def read_id
  @id
end
read_name() click to toggle source
# File lib/play_store_info/app_parser.rb, line 24
def read_name
  name = @body.xpath('//div[@itemprop="name"]/div/text()').text

  raise AppNotFound if name.empty?

  # get the app proper name in case the title contains some description
  name.split(' - ').first.strip
end